Skip to content

Commit 5fd12cb

Browse files
[GR-70300] ConditionalNode.canonical: accept null smallestCompareWidth.
PullRequest: graal/22299
2 parents d5a4177 + b733ce3 commit 5fd12cb

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
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

espresso-compiler-stub/mx.espresso-compiler-stub/mx_espresso_compiler_stub.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import mx_sdk_vm
2828
import mx_gate
2929

30-
from mx_espresso import _espresso_stability, _has_native_espresso_standalone, _send_sigquit, get_java_home_dep, _jdk_lib_dir, jvm_standalone_with_llvm
30+
from mx_espresso import _espresso_stability, _send_sigquit, get_java_home_dep, _jdk_lib_dir, jvm_standalone_with_llvm
3131
from mx_sdk_vm_ng import _find_native_image_command, ThinLauncherProject # pylint: disable=unused-import
3232
from mx_sdk_vm_impl import get_final_graalvm_distribution, has_component, graalvm_skip_archive
3333

@@ -113,7 +113,7 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
113113
native = create_ni_standalone('ESPRESSO_NATIVE_STANDALONE', register_distribution)
114114
jvm = create_ni_standalone('ESPRESSO_JVM_STANDALONE', register_distribution)
115115
if not (native or jvm):
116-
raise mx.abort("Couldn't create any Espresso native-image standalone")
116+
mx.warn("Couldn't create any Espresso native-image standalone")
117117

118118
def _run_espresso_native_image_launcher(args, cwd=None, nonZeroIsFatal=True, out=None, err=None, timeout=None, mode=None):
119119
extra_args = ['-J--vm.' + arg for arg in mx_gate.get_jacoco_agent_args() or []]
@@ -139,10 +139,16 @@ def _run_espresso_native_image_launcher(args, cwd=None, nonZeroIsFatal=True, out
139139
return mx.run([native_image_command] + extra_args + args, cwd=cwd, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, timeout=timeout, on_timeout=_send_sigquit)
140140

141141
def _detect_espresso_native_image_mode():
142-
if _has_native_espresso_standalone() and exists(mx.distribution('ESPRESSO_NI_NATIVE_STANDALONE').get_output()):
142+
native_dist = mx.distribution('ESPRESSO_NI_NATIVE_STANDALONE', fatalIfMissing=False)
143+
jvm_dist = mx.distribution('ESPRESSO_JVM_NATIVE_STANDALONE', fatalIfMissing=False)
144+
if native_dist and exists(native_dist.get_output()):
143145
return 'native'
144-
else:
146+
elif jvm_dist and exists(jvm_dist.get_output()):
145147
return 'jvm'
148+
elif jvm_dist or native_dist:
149+
raise mx.abort("No espresso Native Image Standalone is built")
150+
else:
151+
raise mx.abort("No espresso Native Image Standalone is available (see warnings above)")
146152

147153
def _run_espresso_native_image_jvm_launcher(args, cwd=None, nonZeroIsFatal=True, out=None, err=None, timeout=None):
148154
return _run_espresso_native_image_launcher(args, cwd, nonZeroIsFatal, out, err, timeout, mode='jvm')

espresso-compiler-stub/src/com.oracle.truffle.espresso.graal/src/com/oracle/truffle/espresso/graal/DummyLoweringProvider.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
import jdk.vm.ci.code.TargetDescription;
3636
import jdk.vm.ci.meta.JavaKind;
3737

38+
/**
39+
* Lowering provider used as the "host" lowering provider when running the native image generator on
40+
* espresso.
41+
* <p>
42+
* It is used as part of {code
43+
* com.oracle.svm.hosted.substitute.AutomaticUnsafeTransformationSupport} while parsing methods and
44+
* canonicalizing graphs. This dummy version tries to provide as neutral answers as possible.
45+
* <p>
46+
* See also {@code com.oracle.graal.pointsto.util.GraalAccess} for how the native image generator
47+
* accesses the "host" providers.
48+
*/
3849
public final class DummyLoweringProvider implements LoweringProvider {
3950
private final TargetDescription target;
4051

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/ByteFormattingUtil.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525
package com.oracle.svm.core.util;
2626

2727
public class ByteFormattingUtil {
28-
// "123.12KiB".length() = 9, holds as long as it's not >= 1000GiB
28+
/**
29+
* {@code "123.12KiB".length() = 9} almost always holds as long as the value is not >= 1000GiB
30+
* and {@link String#format} floating point rounding does not bump the whole part to 4 digits
31+
* (e.g. {@code String.format("%.2f", 999.995D) == "1000.00"}).
32+
*/
2933
private static final int MAX_WIDTH = 9;
34+
3035
public static final String RIGHT_ALIGNED_FORMAT = "%" + MAX_WIDTH + "s";
3136

3237
private enum Unit {
@@ -61,9 +66,6 @@ public static String bytesToHumanGB(long bytes) {
6166
}
6267

6368
private static String toHuman(long value, Unit unit) {
64-
long scaled = value / unit.value;
65-
String string = "%.2f%s".formatted((double) scaled, unit.toString());
66-
assert string.length() <= MAX_WIDTH || value >= 1000L * Unit.GiB.value : value;
67-
return string;
69+
return "%.2f%s".formatted((double) value / (double) unit.value, unit.toString());
6870
}
6971
}

0 commit comments

Comments
 (0)