From 8aec1f54bd3572eb2f758cc054fa4fea3bd568cc Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Thu, 2 May 2024 18:57:22 +0200 Subject: [PATCH 1/6] Bump release version to 23.0.4.1 Mark it as non-release. --- compiler/mx.compiler/suite.py | 4 ++-- espresso/mx.espresso/suite.py | 4 ++-- regex/mx.regex/suite.py | 4 ++-- sdk/mx.sdk/suite.py | 4 ++-- substratevm/mx.substratevm/suite.py | 4 ++-- tools/mx.tools/suite.py | 4 ++-- truffle/mx.truffle/suite.py | 4 ++-- vm/mx.vm/suite.py | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/mx.compiler/suite.py b/compiler/mx.compiler/suite.py index 910c91335e3c..288abc267805 100644 --- a/compiler/mx.compiler/suite.py +++ b/compiler/mx.compiler/suite.py @@ -4,8 +4,8 @@ "sourceinprojectwhitelist" : [], "groupId" : "org.graalvm.compiler", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "url" : "http://www.graalvm.org/", "developer" : { "name" : "GraalVM Development", diff --git a/espresso/mx.espresso/suite.py b/espresso/mx.espresso/suite.py index fa1d179f325f..77278b997828 100644 --- a/espresso/mx.espresso/suite.py +++ b/espresso/mx.espresso/suite.py @@ -23,8 +23,8 @@ suite = { "mxversion": "6.17.0", "name": "espresso", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "groupId" : "org.graalvm.espresso", "url" : "https://www.graalvm.org/reference-manual/java-on-truffle/", "developer" : { diff --git a/regex/mx.regex/suite.py b/regex/mx.regex/suite.py index d3ee9caddde7..ea47e7fc1b20 100644 --- a/regex/mx.regex/suite.py +++ b/regex/mx.regex/suite.py @@ -43,8 +43,8 @@ "name" : "regex", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "groupId" : "org.graalvm.regex", "url" : "http://www.graalvm.org/", "developer" : { diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index 6dc751c84a45..92211c8cd645 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -41,8 +41,8 @@ suite = { "mxversion": "6.17.0", "name" : "sdk", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "sourceinprojectwhitelist" : [], "url" : "https://github.com/oracle/graal", "groupId" : "org.graalvm.sdk", diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index ad2ed11ac34a..074e5a52e850 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -2,8 +2,8 @@ suite = { "mxversion": "6.17.0", "name": "substratevm", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "url" : "https://github.com/oracle/graal/tree/master/substratevm", "groupId" : "org.graalvm.nativeimage", diff --git a/tools/mx.tools/suite.py b/tools/mx.tools/suite.py index ab00884c8fb4..710e38f41dca 100644 --- a/tools/mx.tools/suite.py +++ b/tools/mx.tools/suite.py @@ -26,8 +26,8 @@ "defaultLicense" : "GPLv2-CPE", "groupId" : "org.graalvm.tools", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "url" : "http://openjdk.java.net/projects/graal", "developer" : { "name" : "GraalVM Development", diff --git a/truffle/mx.truffle/suite.py b/truffle/mx.truffle/suite.py index a258dc4275b1..658b310f7869 100644 --- a/truffle/mx.truffle/suite.py +++ b/truffle/mx.truffle/suite.py @@ -41,8 +41,8 @@ suite = { "mxversion": "6.17.0", "name" : "truffle", - "version" : "23.0.4.0", - "release" : True, + "version" : "23.0.4.1", + "release" : False, "groupId" : "org.graalvm.truffle", "sourceinprojectwhitelist" : [], "url" : "http://openjdk.java.net/projects/graal", diff --git a/vm/mx.vm/suite.py b/vm/mx.vm/suite.py index edb5ba071c62..dfd9869727cf 100644 --- a/vm/mx.vm/suite.py +++ b/vm/mx.vm/suite.py @@ -1,8 +1,8 @@ suite = { "name": "vm", - "version" : "23.0.4.0", + "version" : "23.0.4.1", "mxversion": "6.17.0", - "release" : True, + "release" : False, "groupId" : "org.graalvm", "url" : "http://www.graalvm.org/", From cef6367f679354434478b8e54b674a4fc2e24b2f Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Fri, 22 Dec 2023 10:39:26 +0100 Subject: [PATCH 2/6] Deprecate ZeroExtendNode.inputAlwaysPositive. (cherry picked from commit de23cc6b87ce34ad8ac2e9ee622c101648227dc9) --- .../amd64/AMD64HotSpotAddressLowering.java | 4 ++-- .../compiler/nodes/calc/SignExtendNode.java | 2 +- .../compiler/nodes/calc/ZeroExtendNode.java | 15 ++++----------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotAddressLowering.java b/compiler/src/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotAddressLowering.java index 7b958f650493..b5231c475d3b 100644 --- a/compiler/src/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotAddressLowering.java +++ b/compiler/src/org.graalvm.compiler.hotspot.amd64/src/org/graalvm/compiler/hotspot/amd64/AMD64HotSpotAddressLowering.java @@ -187,14 +187,14 @@ private static ValueNode signExtend(ValueNode input, LoopEx loop) { if (init >= 0 && extremum >= 0) { long shortestTrip = (extremum - init) / stride + 1; if (countedLoopInfo.constantMaxTripCount().equals(shortestTrip)) { - return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true)); + return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, false)); } } } if (countedLoopInfo.getLimitCheckedIV() == inductionVariable && inductionVariable.direction() == InductionVariable.Direction.Up && (countedLoopInfo.getOverFlowGuard() != null || countedLoopInfo.counterNeverOverflows())) { - return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true)); + return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, false)); } } } diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignExtendNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignExtendNode.java index 3c006ec01eed..4d7526109ade 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignExtendNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/SignExtendNode.java @@ -124,7 +124,7 @@ private static ValueNode canonical(SignExtendNode self, ValueNode forValue, int if ((inputStamp.mayBeSet() & (1L << (inputBits - 1))) == 0L) { // 0xxx -(sign-extend)-> 0000 0xxx // ==> 0xxx -(zero-extend)-> 0000 0xxx - return ZeroExtendNode.create(forValue, inputBits, resultBits, view, true); + return ZeroExtendNode.create(forValue, inputBits, resultBits, view, false); } } if (forValue instanceof NarrowNode) { diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/ZeroExtendNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/ZeroExtendNode.java index 9e903c274f98..6e134cc8a43b 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/ZeroExtendNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/ZeroExtendNode.java @@ -35,6 +35,7 @@ import org.graalvm.compiler.core.common.type.IntegerStamp; import org.graalvm.compiler.core.common.type.PrimitiveStamp; import org.graalvm.compiler.core.common.type.Stamp; +import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.NodeClass; import org.graalvm.compiler.lir.gen.ArithmeticLIRGeneratorTool; import org.graalvm.compiler.nodeinfo.NodeInfo; @@ -67,14 +68,15 @@ public ZeroExtendNode(ValueNode input, int resultBits) { public ZeroExtendNode(ValueNode input, int inputBits, int resultBits, boolean inputAlwaysPositive) { super(TYPE, getArithmeticOpTable(input).getZeroExtend(), inputBits, resultBits, input); this.inputAlwaysPositive = inputAlwaysPositive; + GraalError.guarantee(!inputAlwaysPositive, "ZeroExtendNode.inputAlwaysPositive is deprecated."); } public static ValueNode create(ValueNode input, int resultBits, NodeView view) { - return create(input, PrimitiveStamp.getBits(input.stamp(view)), resultBits, view, inputAlwaysPositive(input)); + return create(input, PrimitiveStamp.getBits(input.stamp(view)), resultBits, view, false); } public static ValueNode create(ValueNode input, int inputBits, int resultBits, NodeView view) { - return create(input, inputBits, resultBits, view, inputAlwaysPositive(input)); + return create(input, inputBits, resultBits, view, false); } public static ValueNode create(ValueNode input, int inputBits, int resultBits, NodeView view, boolean alwaysPositive) { @@ -86,15 +88,6 @@ public static ValueNode create(ValueNode input, int inputBits, int resultBits, N return canonical(null, input, inputBits, resultBits, view, alwaysPositive); } - private static boolean inputAlwaysPositive(ValueNode v) { - Stamp s = v.stamp(NodeView.DEFAULT); - if (s instanceof IntegerStamp) { - return ((IntegerStamp) s).isPositive(); - } else { - return false; - } - } - @Override protected IntegerConvertOp getOp(ArithmeticOpTable table) { return table.getZeroExtend(); From 9832d435f2a32ec6c79a20a737a8f9bfa4db92bb Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Thu, 18 Jan 2024 16:09:11 +0100 Subject: [PATCH 3/6] use safe abs in loop opts (cherry picked from commit 3d0266ba325298d6c71209d14171a769ece6a303) --- .../loop/phases/LoopPredicationPhase.java | 2 ++ .../graalvm/compiler/nodes/loop/LoopEx.java | 14 ++++++-- .../phases/common/util/LoopUtility.java | 33 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java b/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java index b52a4c070fa7..ed2218e9cd9b 100644 --- a/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java +++ b/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java @@ -114,6 +114,8 @@ protected void run(StructuredGraph graph, MidTierContext context) { final boolean inverted = loop.counted().isInverted(); if ((((IntegerStamp) counter.valueNode().stamp(NodeView.DEFAULT)).getBits() == 32) && !counted.isUnsignedCheck() && + // math.abs can overflow here but only to min again which is + // never == 1 ((condition != NE && condition != EQ) || (counter.isConstantStride() && Math.abs(counter.constantStride()) == 1)) && (loop.loopBegin().isMainLoop() || loop.loopBegin().isSimpleLoop())) { NodeIterable guards = loop.whole().nodes().filter(GuardNode.class); diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java index a5052d7dc47c..7727c0ad8f67 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java @@ -332,7 +332,7 @@ public boolean detectCounted() { // signed: i < MAX_INT } else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedUpperBound()) { unsigned = true; - } else if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1 || initStamp.upperBound() > limitStamp.lowerBound()) { + } else if (!iv.isConstantStride() || !absStrideIsOne(iv) || initStamp.upperBound() > limitStamp.lowerBound()) { return false; } } else if (iv.direction() == Direction.Down) { @@ -340,7 +340,7 @@ public boolean detectCounted() { // signed: MIN_INT > i } else if (limitStamp.asConstant() != null && limitStamp.asConstant().asLong() == counterStamp.unsignedLowerBound()) { unsigned = true; - } else if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1 || initStamp.lowerBound() < limitStamp.upperBound()) { + } else if (!iv.isConstantStride() || !absStrideIsOne(iv) || initStamp.lowerBound() < limitStamp.upperBound()) { return false; } } else { @@ -387,6 +387,16 @@ public boolean detectCounted() { return false; } + public static boolean absStrideIsOne(InductionVariable limitCheckedIV) { + final long absStride; + try { + absStride = LoopUtility.abs(limitCheckedIV.constantStride(), IntegerStamp.getBits(limitCheckedIV.strideNode().stamp(NodeView.DEFAULT))); + } catch (ArithmeticException e) { + return false; + } + return absStride == 1; + } + public boolean isCfgLoopExit(AbstractBeginNode begin) { HIRBlock block = data.getCFG().blockFor(begin); return loop.getDepth() > block.getLoopDepth() || loop.isNaturalExit(block); diff --git a/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java b/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java index 59434d6166c3..a325b9789cab 100644 --- a/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java +++ b/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java @@ -28,6 +28,7 @@ import org.graalvm.compiler.core.common.type.IntegerStamp; import org.graalvm.compiler.core.common.type.Stamp; +import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Graph.NodeEvent; import org.graalvm.compiler.graph.Graph.NodeEventScope; import org.graalvm.compiler.nodes.LoopExitNode; @@ -48,6 +49,38 @@ public class LoopUtility { + public static boolean canTakeAbs(long l, int bits) { + try { + abs(l, bits); + return true; + } catch (ArithmeticException e) { + return false; + } + } + + /** + * Compute {@link Math#abs(long)} for the given arguments and the given bit size. Throw a + * {@link ArithmeticException} if the abs operation would overflow. + */ + public static long abs(long l, int bits) throws ArithmeticException { + if (bits == 32) { + if (l == Integer.MIN_VALUE) { + throw new ArithmeticException("Abs on Integer.MIN_VALUE would cause an overflow because abs(Integer.MIN_VALUE) = Integer.MAX_VALUE + 1 which does not fit in int (32bits)"); + } else { + final int i = (int) l; + return Math.abs(i); + } + } else if (bits == 64) { + if (l == Long.MIN_VALUE) { + throw new ArithmeticException("Abs on Long.MIN_VALUE would cause an overflow because abs(Long.MIN_VALUE) = Long.MAX_VALUE + 1 which does not fit in int (32bits)"); + } else { + return Math.abs(l); + } + } else { + throw GraalError.shouldNotReachHere("Must be one of java's core datatypes int/long but is " + bits); + } + } + public static boolean isNumericInteger(ValueNode v) { Stamp s = v.stamp(NodeView.DEFAULT); return s instanceof IntegerStamp; From 848c6b84b60a7e06fe0a66c3573b36ffdcc16e10 Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Tue, 23 Jan 2024 13:47:56 +0100 Subject: [PATCH 4/6] fix comment (cherry picked from commit 83c699edbfc6af7b6effeb3ad536fbc6531edf3a) (cherry picked from commit dbf260a5db063f28b0244f3efd9fd8be1c47dbac) --- .../org/graalvm/compiler/phases/common/util/LoopUtility.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java b/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java index a325b9789cab..57e549801225 100644 --- a/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java +++ b/compiler/src/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/util/LoopUtility.java @@ -65,14 +65,14 @@ public static boolean canTakeAbs(long l, int bits) { public static long abs(long l, int bits) throws ArithmeticException { if (bits == 32) { if (l == Integer.MIN_VALUE) { - throw new ArithmeticException("Abs on Integer.MIN_VALUE would cause an overflow because abs(Integer.MIN_VALUE) = Integer.MAX_VALUE + 1 which does not fit in int (32bits)"); + throw new ArithmeticException("Abs on Integer.MIN_VALUE would cause an overflow because abs(Integer.MIN_VALUE) = Integer.MAX_VALUE + 1 which does not fit in int (32 bits)"); } else { final int i = (int) l; return Math.abs(i); } } else if (bits == 64) { if (l == Long.MIN_VALUE) { - throw new ArithmeticException("Abs on Long.MIN_VALUE would cause an overflow because abs(Long.MIN_VALUE) = Long.MAX_VALUE + 1 which does not fit in int (32bits)"); + throw new ArithmeticException("Abs on Long.MIN_VALUE would cause an overflow because abs(Long.MIN_VALUE) = Long.MAX_VALUE + 1 which does not fit in long (64 bits)"); } else { return Math.abs(l); } From 9a4c8d88b654a82fad2b8ff9d9ef575110691828 Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Tue, 23 Jan 2024 13:55:27 +0100 Subject: [PATCH 5/6] loop ex: allow overflow in math.abs for stride !=1 checks, it does not matter, in case of overflow the value is still different (cherry picked from commit ac0fc684c9b78b337873d5789d8886cd6a93cea9) (cherry picked from commit 432915f08f0728882c4b9d2929afdbb236fcb038) --- .../src/org/graalvm/compiler/nodes/loop/LoopEx.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java index 7727c0ad8f67..9221e841ea0e 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/loop/LoopEx.java @@ -388,13 +388,12 @@ public boolean detectCounted() { } public static boolean absStrideIsOne(InductionVariable limitCheckedIV) { - final long absStride; - try { - absStride = LoopUtility.abs(limitCheckedIV.constantStride(), IntegerStamp.getBits(limitCheckedIV.strideNode().stamp(NodeView.DEFAULT))); - } catch (ArithmeticException e) { - return false; - } - return absStride == 1; + /* + * While Math.abs can overflow for MIN_VALUE it is fine here. In case of overflow we still + * get a value != 1 (namely MIN_VALUE again). Overflow handling for the limit checked IV is + * done in CountedLoopInfo and is an orthogonal issue. + */ + return Math.abs(limitCheckedIV.constantStride()) == 1; } public boolean isCfgLoopExit(AbstractBeginNode begin) { From 8516fb9fc404d337f5a54e248f25652e5aa2bb57 Mon Sep 17 00:00:00 2001 From: David Leopoldseder Date: Fri, 26 Jan 2024 14:30:23 +0100 Subject: [PATCH 6/6] reuse loopex.absStrideIsOne (cherry picked from commit 429b3f9fb983e98bd87b8d440c43195e4d75f0d1) (cherry picked from commit c9530f10391109977eb8774ce8bb1ffba6cfffbd) --- .../graalvm/compiler/loop/phases/LoopPredicationPhase.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java b/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java index ed2218e9cd9b..79f3b6134381 100644 --- a/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java +++ b/compiler/src/org.graalvm.compiler.loop.phases/src/org/graalvm/compiler/loop/phases/LoopPredicationPhase.java @@ -112,11 +112,8 @@ protected void run(StructuredGraph graph, MidTierContext context) { final InductionVariable counter = counted.getLimitCheckedIV(); final Condition condition = ((CompareNode) counted.getLimitTest().condition()).condition().asCondition(); final boolean inverted = loop.counted().isInverted(); - if ((((IntegerStamp) counter.valueNode().stamp(NodeView.DEFAULT)).getBits() == 32) && - !counted.isUnsignedCheck() && - // math.abs can overflow here but only to min again which is - // never == 1 - ((condition != NE && condition != EQ) || (counter.isConstantStride() && Math.abs(counter.constantStride()) == 1)) && + if ((((IntegerStamp) counter.valueNode().stamp(NodeView.DEFAULT)).getBits() == 32) && !counted.isUnsignedCheck() && + ((condition != NE && condition != EQ) || (counter.isConstantStride() && LoopEx.absStrideIsOne(counter))) && (loop.loopBegin().isMainLoop() || loop.loopBegin().isSimpleLoop())) { NodeIterable guards = loop.whole().nodes().filter(GuardNode.class); if (LoopPredicationMainPath.getValue(graph.getOptions())) {