JDK-8220376 : C2: Int >0 not recognized as !=0 for div by 0 check
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-03-08
  • Updated: 2020-11-24
  • Resolved: 2019-11-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14
14 b25Fixed
Related Reports
Relates :  
Relates :  
Description
C2 knows that the "int x" is not 0 at the division when using the check "x != 0" in the simple test program below.
However, when using "x > 0", it generates an unnecessary zero check and an uncommon trap. I believe this is a bug. C2 should treat x as non-zero after having found the lower bound "x > 0".


TestDiv.java:
public class TestDiv{

  public static int test_method(int x) {
      if (x > 0) { // x != 0 helps C2, why not x > 0?
          return 3 % x;
      }
      return 0;
  }

  public static void main(String args[]) {
    int result = test_method(3);
    System.out.println("result: " + result);
  }
}

Command line:
jdk-jdk-fastdebug/images/jdk/bin/java -XX:+PrintOptoAssembly -XX:-TieredCompilation -XX:CompileCommand=compileonly,TestDiv::test_method -Xcomp TestDiv

Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/54cf02d52c1b User: phedlin Date: 2019-11-27 10:12:38 +0000
27-11-2019