diff --git a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CountedLoopTest.java b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CountedLoopTest.java index 2951d2f9b548..9c6be64ebd6c 100644 --- a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CountedLoopTest.java +++ b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CountedLoopTest.java @@ -46,6 +46,8 @@ import org.graalvm.compiler.nodes.util.GraphUtil; import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.phases.OptimisticOptimizations; + +import org.junit.Ignore; import org.junit.Test; import jdk.vm.ci.code.InstalledCode; @@ -522,11 +524,13 @@ public void decrementUnsigned6() { } @Test + @Ignore("GR-54120: Loops requiring overflow to terminate must not be counted in graal, CountedLoopInfo API does not support that") public void decrementUnsigned7() { testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 10, 0, 1); } @Test + @Ignore("GR-54120: Loops requiring overflow to terminate must not be counted in graal, CountedLoopInfo API does not support that") public void decrementUnsigned8() { testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 11, 0, 2); } diff --git a/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/DerivedOffsetInductionVariable.java b/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/DerivedOffsetInductionVariable.java index 53292eb163e7..2153fe0c119f 100644 --- a/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/DerivedOffsetInductionVariable.java +++ b/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/DerivedOffsetInductionVariable.java @@ -35,6 +35,7 @@ import org.graalvm.compiler.nodes.calc.AddNode; import org.graalvm.compiler.nodes.calc.BinaryArithmeticNode; import org.graalvm.compiler.nodes.calc.IntegerConvertNode; +import org.graalvm.compiler.nodes.calc.IntegerExactArithmeticNode; import org.graalvm.compiler.nodes.calc.NegateNode; import org.graalvm.compiler.nodes.calc.SubNode; @@ -186,7 +187,8 @@ private long opSafe(long b, long o) throws ArithmeticException { if (base.valueNode() == value.getX()) { return subtractExact(IntegerStamp.getBits(offset.stamp(NodeView.DEFAULT)), b, o); } else { - assert base.valueNode() == value.getY() : String.format("[base]=%s;[value]=%s", base.valueNode(), value.getY()); + assert base.valueNode() == value.getY() || (base instanceof BasicInductionVariable && ((BasicInductionVariable) base).getOp() instanceof IntegerExactArithmeticNode) : String.format( + "[base]=%s;[value]=%s", base, value); return subtractExact(IntegerStamp.getBits(offset.stamp(NodeView.DEFAULT)), b, o); } } @@ -201,7 +203,7 @@ private ValueNode op(ValueNode b, ValueNode o) { if (base.valueNode() == value.getX()) { return sub(graph(), b, o); } else { - assert base.valueNode() == value.getY(); + assert base.valueNode() == value.getY() || (base instanceof BasicInductionVariable && ((BasicInductionVariable) base).getOp() instanceof IntegerExactArithmeticNode); return sub(graph(), o, b); } } diff --git a/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java b/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java index bb8754d3c57e..1b513aad7f5c 100644 --- a/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java +++ b/compiler/src/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/LoopEx.java @@ -308,7 +308,7 @@ public boolean detectCounted() { if (iv.direction() == Direction.Up) { if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.upperBound()) { // signed: i < MAX_INT - } else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedUpperBound()) { + } else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedUpperBound() && IntegerStamp.sameSign(initStamp, limitStamp)) { unsigned = true; } else if (!iv.isConstantStride() || !absStrideIsOne(iv) || initStamp.upperBound() > limitStamp.lowerBound()) { return false; @@ -316,7 +316,7 @@ public boolean detectCounted() { } else if (iv.direction() == Direction.Down) { if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.lowerBound()) { // signed: MIN_INT > i - } else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedLowerBound()) { + } else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedLowerBound() && IntegerStamp.sameSign(initStamp, limitStamp)) { unsigned = true; } else if (!iv.isConstantStride() || !absStrideIsOne(iv) || initStamp.lowerBound() < limitStamp.upperBound()) { return false; diff --git a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerExactArithmeticNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/IntegerExactArithmeticNode.java similarity index 95% rename from compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerExactArithmeticNode.java rename to compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/IntegerExactArithmeticNode.java index 54fd57711d87..d9c2b54527cb 100644 --- a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerExactArithmeticNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/IntegerExactArithmeticNode.java @@ -22,7 +22,7 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package org.graalvm.compiler.replacements.nodes.arithmetic; +package org.graalvm.compiler.nodes.calc; public interface IntegerExactArithmeticNode { } diff --git a/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java b/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java index 5684339acd21..b28758121a10 100644 --- a/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java +++ b/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java @@ -41,13 +41,13 @@ import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; import org.graalvm.compiler.nodes.ValueNode; +import org.graalvm.compiler.nodes.calc.IntegerExactArithmeticNode; import org.graalvm.compiler.nodes.spi.LoweringTool; import org.graalvm.compiler.phases.common.CanonicalizerPhase; import org.graalvm.compiler.phases.common.GuardLoweringPhase; import org.graalvm.compiler.phases.common.LoweringPhase; import org.graalvm.compiler.phases.tiers.HighTierContext; import org.graalvm.compiler.phases.tiers.MidTierContext; -import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode; import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode; import org.junit.Assert; import org.junit.Test; diff --git a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerAddExactNode.java b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerAddExactNode.java index 1031c9e9e335..44a5821a1374 100644 --- a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerAddExactNode.java +++ b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerAddExactNode.java @@ -39,6 +39,7 @@ import org.graalvm.compiler.nodes.NodeView; import org.graalvm.compiler.nodes.ValueNode; import org.graalvm.compiler.nodes.calc.AddNode; +import org.graalvm.compiler.nodes.calc.IntegerExactArithmeticNode; import org.graalvm.compiler.nodes.extended.GuardedNode; import org.graalvm.compiler.nodes.extended.GuardingNode; diff --git a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerMulExactNode.java b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerMulExactNode.java index a165ee588823..668cc9855ec1 100644 --- a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerMulExactNode.java +++ b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerMulExactNode.java @@ -29,15 +29,16 @@ import org.graalvm.compiler.core.common.type.IntegerStamp; import org.graalvm.compiler.graph.NodeClass; -import org.graalvm.compiler.graph.spi.CanonicalizerTool; import org.graalvm.compiler.nodeinfo.InputType; import org.graalvm.compiler.nodeinfo.NodeInfo; import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.NodeView; import org.graalvm.compiler.nodes.ValueNode; +import org.graalvm.compiler.nodes.calc.IntegerExactArithmeticNode; import org.graalvm.compiler.nodes.calc.MulNode; import org.graalvm.compiler.nodes.extended.GuardedNode; import org.graalvm.compiler.nodes.extended.GuardingNode; +import org.graalvm.compiler.graph.spi.CanonicalizerTool; import jdk.vm.ci.meta.JavaConstant; import jdk.vm.ci.meta.JavaKind; diff --git a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerSubExactNode.java b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerSubExactNode.java index 405d178472b3..cd3dcc4a1c68 100644 --- a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerSubExactNode.java +++ b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerSubExactNode.java @@ -35,6 +35,7 @@ import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.NodeView; import org.graalvm.compiler.nodes.ValueNode; +import org.graalvm.compiler.nodes.calc.IntegerExactArithmeticNode; import org.graalvm.compiler.nodes.calc.SubNode; import org.graalvm.compiler.nodes.extended.GuardedNode; import org.graalvm.compiler.nodes.extended.GuardingNode;