(original) (raw)

Hi John,

Nice to hear from you!

I ran a couple of tests on the patch, one of them is:

public class ArrayRangeCheck {
private static Object foo(Object\[\] a, int x) throws Exception {
if (a.length == 0) throw new Exception();
return a\[x & (a.length - 1)\];
}
public static void main(String\[\] args) throws Exception {
Object\[\] a = new Object\[8\];
foo(a, 6);
foo(a, 6);
System.in.read();
}
}

Ran with:

$ java -XX:CompileCommand="compileonly ArrayRangeCheck foo" -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:CompileThreshold=1 -XX:PrintIdealGraphLevel=4 -XX:PrintIdealGraphFile=ideal.xml -XX:+PrintCompilation -XX:+PrintAssembly ArrayRangeCheck

And confirmed that in this case the range check is indeed elided: there's only one a.length != 0 check dominating the actual element load, and the else branch goes to the exception throwing code.

Thanks,
Kris


On Wed, Feb 12, 2014 at 9:47 PM, John Rose <john.r.rose@oracle.com> wrote:
One point behind the bug report is to give a little reward to Java coders who write dominating tests that exclude a.length==0, as:

if (a.length == 0) goAway();
else return a\[i & a.length-1\];

Kris, can your patch do this? The logic in IfNode can probably elide the duplicate dominating test, if the right normalizations occur. 😀

– John

On Feb 12, 2014, at 6:05 PM, Martin Grajcar <maaartinus@gmail.com> wrote:

That's what I've meant with goAway. My point was the jump using already computed flags