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