Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8220376

C2: Int >0 not recognized as !=0 for div by 0 check

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 14
    • 13
    • hotspot
    • b25

      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

            phedlin Patric Hedlin (Inactive)
            mdoerr Martin Doerr
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: