Mercurial > hg > graal-compiler
changeset 22895:262d42eaa97b
Canonicalize single bit tests
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 27 Oct 2015 16:01:15 -0700 |
parents | 6bcd82f2b070 |
children | afe502521189 |
files | graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest11.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTestBase.java graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IntegerEqualsCanonicalizerTest.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java |
diffstat | 4 files changed, 42 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest11.java Tue Oct 27 09:44:24 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest11.java Tue Oct 27 16:01:15 2015 -0700 @@ -33,6 +33,10 @@ * triggered bugs in this phase. */ public class ConditionalEliminationTest11 extends ConditionalEliminationTestBase { + public ConditionalEliminationTest11() { + // Don't disable simplification + super(false); + } @SuppressWarnings("all") public static int referenceSnippet(int a) { @@ -139,7 +143,6 @@ testConditionalElimination("test5Snippet", "test5Snippet"); } - @SuppressWarnings("all") public static int test6Snippet(int a) { if ((a & 8) != 0) { GraalDirectives.deoptimize(); @@ -150,7 +153,6 @@ return 0; } - @SuppressWarnings("all") public static int reference6Snippet(int a) { if ((a & 8) != 0) { GraalDirectives.deoptimize();
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTestBase.java Tue Oct 27 09:44:24 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTestBase.java Tue Oct 27 16:01:15 2015 -0700 @@ -43,6 +43,16 @@ */ public class ConditionalEliminationTestBase extends GraalCompilerTest { + private final boolean disableSimplification; + + protected ConditionalEliminationTestBase() { + disableSimplification = true; + } + + protected ConditionalEliminationTestBase(boolean disableSimplification) { + this.disableSimplification = disableSimplification; + } + protected void testConditionalElimination(String snippet, String referenceSnippet) { testConditionalElimination(snippet, referenceSnippet, false); } @@ -52,7 +62,12 @@ Debug.dump(graph, "Graph"); PhaseContext context = new PhaseContext(getProviders()); CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); - canonicalizer1.disableSimplification(); + if (disableSimplification) { + /** + * Some tests break if simplification is done so only do it when needed. + */ + canonicalizer1.disableSimplification(); + } canonicalizer1.apply(graph, context); new ConvertDeoptimizeToGuardPhase().apply(graph, context); CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IntegerEqualsCanonicalizerTest.java Tue Oct 27 09:44:24 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IntegerEqualsCanonicalizerTest.java Tue Oct 27 16:01:15 2015 -0700 @@ -126,6 +126,19 @@ field = array1Length == (-array2Length) ? 1 : 0; } + public static boolean testNormalIntegerTest(int a) { + return (a & 8) != 0; + } + + public static boolean testAlternateIntegerTest(int a) { + return (a & 8) == 8; + } + + @Test + public void testIntegerTest() { + test("testNormalIntegerTest", "testAlternateIntegerTest"); + } + private void test(String snippet, String referenceSnippet) { StructuredGraph graph = getCanonicalizedGraph(snippet); StructuredGraph referenceGraph = getCanonicalizedGraph(referenceSnippet);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java Tue Oct 27 09:44:24 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java Tue Oct 27 16:01:15 2015 -0700 @@ -169,6 +169,15 @@ } } } + if (nonConstant instanceof AndNode) { + /* + * a & c == c is the same as a & c != 0, if c is a single bit. + */ + AndNode andNode = (AndNode) nonConstant; + if (constant instanceof PrimitiveConstant && Long.bitCount(((PrimitiveConstant) constant).asLong()) == 1 && andNode.getY().isConstant() && andNode.getY().asJavaConstant().equals(constant)) { + return new LogicNegationNode(new IntegerTestNode(andNode.getX(), andNode.getY())); + } + } return super.canonicalizeSymmetricConstant(tool, constant, nonConstant, mirrored); }