Mercurial > hg > truffle
changeset 10046:09baba95f1ae
detect distinct values by looking at integer masks
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 14 Jun 2013 16:24:42 +0200 |
parents | a4e7a7dc74f3 |
children | 30499c84823d |
files | graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StampCanonicalizerTest.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/IntegerStamp.java |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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