Skip to content

Commit bcc5643

Browse files
Accept null smallestCompareWidth in caonicalizations.
* `ConditiionalNode.canonical` should accept `null` and go through `CanonicalizerTool.smallestCompareWidth` instead of directly querying the `LoweringProvider`. * The neutral `null` value is used in platform-independent contexts.
1 parent 1427c2c commit bcc5643

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/ConditionalNode.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ public ValueNode canonical(CanonicalizerTool tool) {
126126
return result;
127127
}
128128

129-
if (tool != null && stamp instanceof IntegerStamp integerStamp && integerStamp.getBits() >= tool.getLowerer().smallestCompareWidth()) {
130-
ValueNode minMaxSynonym = MinMaxNode.fromConditional(condition, trueValue, falseValue, view);
131-
if (minMaxSynonym != null) {
132-
return minMaxSynonym;
129+
if (tool != null && stamp instanceof IntegerStamp integerStamp) {
130+
Integer smallestCompareWidth = tool.smallestCompareWidth();
131+
if (smallestCompareWidth != null && integerStamp.getBits() >= smallestCompareWidth) {
132+
ValueNode minMaxSynonym = MinMaxNode.fromConditional(condition, trueValue, falseValue, view);
133+
if (minMaxSynonym != null) {
134+
return minMaxSynonym;
135+
}
133136
}
134137
}
135138

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/calc/MinMaxNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ private static boolean equalOrOffBy1(Signedness signedness, ValueNode a, ValueNo
300300
*/
301301
protected static ValueNode maybeExtendForCompare(ValueNode value, LoweringProvider lowerer, Signedness signedness) {
302302
Stamp fromStamp = value.stamp(NodeView.DEFAULT);
303-
if (fromStamp instanceof PrimitiveStamp && PrimitiveStamp.getBits(fromStamp) < lowerer.smallestCompareWidth()) {
304-
Stamp toStamp = IntegerStamp.create(lowerer.smallestCompareWidth());
303+
Integer smallestCompareWidth = lowerer.smallestCompareWidth();
304+
if (fromStamp instanceof PrimitiveStamp && smallestCompareWidth != null && PrimitiveStamp.getBits(fromStamp) < smallestCompareWidth) {
305+
Stamp toStamp = IntegerStamp.create(smallestCompareWidth);
305306
boolean zeroExtend = (signedness == Signedness.UNSIGNED);
306307
return IntegerConvertNode.convert(value, toStamp, zeroExtend, NodeView.DEFAULT);
307308
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/spi/LoweringProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public interface LoweringProvider {
5353
ValueNode reconstructArrayIndex(JavaKind elementKind, AddressNode address);
5454

5555
/**
56-
* Indicates the smallest width for comparing an integer value on the target platform.
56+
* Indicates the smallest width for comparing an integer value on the target platform. Returns
57+
* {@code null} when this information is not available. This can be the case when this lowering
58+
* provider is being used in a platform independent context (e.g., canonicalization).
5759
*/
5860
Integer smallestCompareWidth();
5961

0 commit comments

Comments
 (0)