# HG changeset patch # User Lukas Stadler # Date 1371219882 -7200 # Node ID 09baba95f1aee0f59dc7395d866c1a5854013e66 # Parent a4e7a7dc74f3b20fe5ce2a382b7fb1d06f157897 detect distinct values by looking at integer masks diff -r a4e7a7dc74f3 -r 09baba95f1ae graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StampCanonicalizerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StampCanonicalizerTest.java Fri Jun 14 16:23:53 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StampCanonicalizerTest.java Fri Jun 14 16:24:42 2013 +0200 @@ -96,6 +96,17 @@ testZeroReturn("divStamp2"); } + public static int distinctMask(int a, int b) { + int x = a & 0xaaaa; + int y = (b & 0x5555) | 0x1; + return x == y ? 1 : 0; + } + + @Test + public void testDistinctMask() { + testZeroReturn("distinctMask"); + } + private void testZeroReturn(String methodName) { StructuredGraph graph = parse(methodName); new CanonicalizerPhase.Instance(runtime(), new Assumptions(false), true).apply(graph); diff -r a4e7a7dc74f3 -r 09baba95f1ae graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java Fri Jun 14 16:23:53 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java Fri Jun 14 16:24:42 2013 +0200 @@ -129,7 +129,15 @@ @Override public boolean alwaysDistinct(Stamp otherStamp) { IntegerStamp other = (IntegerStamp) otherStamp; - return lowerBound > other.upperBound || upperBound < other.lowerBound; + if (lowerBound > other.upperBound || upperBound < other.lowerBound) { + return true; + } else { + if ((mask & other.mask) == 0) { + // zero is the only common value if the masks don't overlap => check for non-zero + return lowerBound > 0 || upperBound < 0 || other.lowerBound > 0 || other.upperBound < 0; + } + return false; + } } @Override