Mercurial > hg > graal-compiler
changeset 22781:4c101dcc419d
Add new canonicalization for x - y == 0 to x == y in IntegerEqualsNode.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 08 Oct 2015 15:57:40 +0200 |
parents | a12d8efbf93a |
children | ef56f81f88ee |
files | 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 | 3 files changed, 27 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTestBase.java Wed Oct 07 14:12:48 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTestBase.java Thu Oct 08 15:57:40 2015 +0200 @@ -60,6 +60,7 @@ canonicalizer.apply(graph, context); canonicalizer.apply(graph, context); StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES); + new ConvertDeoptimizeToGuardPhase().apply(referenceGraph, context); if (applyConditionalEliminationOnReference) { new DominatorConditionalEliminationPhase(true).apply(referenceGraph, context); canonicalizer.apply(referenceGraph, context);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IntegerEqualsCanonicalizerTest.java Wed Oct 07 14:12:48 2015 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IntegerEqualsCanonicalizerTest.java Thu Oct 08 15:57:40 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,10 +33,29 @@ public class IntegerEqualsCanonicalizerTest extends GraalCompilerTest { @Test + public void testSubtractEqualsZero() { + test("testSubtractEqualsZeroSnippet", "testSubtractEqualsZeroReference"); + } + + public static int testSubtractEqualsZeroReference(int a, int b) { + if (a == b) { + return 1; + } + return 0; + } + + public static int testSubtractEqualsZeroSnippet(int a, int b) { + if (a - b == 0) { + return 1; + } + return 0; + } + + /** + * Tests the canonicalization of (x >>> const) == 0 to x |test| (-1 << const). + */ + @Test public void testShiftEquals() { - /* - * tests the canonicalization of (x >>> const) == 0 to x |test| (-1 << const) - */ test("testShiftEqualsSnippet", "testShiftEqualsReference"); }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java Wed Oct 07 14:12:48 2015 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java Thu Oct 08 15:57:40 2015 +0200 @@ -126,6 +126,9 @@ if (nonConstant instanceof AndNode) { AndNode andNode = (AndNode) nonConstant; return new IntegerTestNode(andNode.getX(), andNode.getY()); + } else if (nonConstant instanceof SubNode) { + SubNode subNode = (SubNode) nonConstant; + return IntegerEqualsNode.create(subNode.getX(), subNode.getY(), tool.getConstantReflection()); } else if (nonConstant instanceof ShiftNode && nonConstant.stamp() instanceof IntegerStamp) { if (nonConstant instanceof LeftShiftNode) { LeftShiftNode shift = (LeftShiftNode) nonConstant;