41
41
import java .util .BitSet ;
42
42
import java .util .List ;
43
43
44
- import jdk .graal .compiler .nodes .calc .AndNode ;
45
- import jdk .graal .compiler .nodes .calc .OrNode ;
46
44
import org .graalvm .word .LocationIdentity ;
47
45
48
46
import jdk .graal .compiler .core .common .memory .BarrierType ;
82
80
import jdk .graal .compiler .nodes .ValueNode ;
83
81
import jdk .graal .compiler .nodes .ValuePhiNode ;
84
82
import jdk .graal .compiler .nodes .calc .AddNode ;
83
+ import jdk .graal .compiler .nodes .calc .AndNode ;
85
84
import jdk .graal .compiler .nodes .calc .ConditionalNode ;
86
85
import jdk .graal .compiler .nodes .calc .FloatingIntegerDivRemNode ;
87
86
import jdk .graal .compiler .nodes .calc .IntegerBelowNode ;
91
90
import jdk .graal .compiler .nodes .calc .IsNullNode ;
92
91
import jdk .graal .compiler .nodes .calc .LeftShiftNode ;
93
92
import jdk .graal .compiler .nodes .calc .NarrowNode ;
93
+ import jdk .graal .compiler .nodes .calc .OrNode ;
94
94
import jdk .graal .compiler .nodes .calc .ReinterpretNode ;
95
95
import jdk .graal .compiler .nodes .calc .RightShiftNode ;
96
96
import jdk .graal .compiler .nodes .calc .SignExtendNode ;
@@ -831,7 +831,7 @@ protected ReadNode createUnsafeRead(StructuredGraph graph, RawLoadNode load, Gua
831
831
} else {
832
832
memoryRead .setGuard (guard );
833
833
}
834
- ValueNode readValue = performBooleanCoercionIfNecessary ( implicitLoadConvert ( graph , readKind , memoryRead , compressible ), readKind );
834
+ ValueNode readValue = implicitUnsafeLoadConvert ( graph , readKind , memoryRead , compressible );
835
835
load .replaceAtUsages (readValue );
836
836
return memoryRead ;
837
837
}
@@ -846,26 +846,18 @@ protected void lowerUnsafeMemoryLoadNode(UnsafeMemoryLoadNode load) {
846
846
// An unsafe read must not float otherwise it may float above
847
847
// a test guaranteeing the read is safe.
848
848
memoryRead .setForceFixed (true );
849
- ValueNode readValue = performBooleanCoercionIfNecessary ( implicitLoadConvert ( graph , readKind , memoryRead , false ), readKind );
849
+ ValueNode readValue = implicitUnsafeLoadConvert ( graph , readKind , memoryRead , false );
850
850
load .replaceAtUsages (readValue );
851
851
graph .replaceFixedWithFixed (load , memoryRead );
852
852
}
853
853
854
- private static ValueNode performBooleanCoercionIfNecessary (ValueNode readValue , JavaKind readKind ) {
855
- StructuredGraph graph = readValue .graph ();
856
- return performBooleanCoercionIfNecessary (readValue , readKind , graph , true );
857
- }
858
-
859
- public static ValueNode performBooleanCoercionIfNecessary (ValueNode readValue , JavaKind readKind , StructuredGraph graph , boolean withGraphAdd ) {
860
- if (readKind == JavaKind .Boolean ) {
861
- IntegerEqualsNode eq = new IntegerEqualsNode (readValue , ConstantNode .forInt (0 , graph ));
862
- ValueNode result = new ConditionalNode (eq , ConstantNode .forBoolean (false , graph ), ConstantNode .forBoolean (true , graph ));
863
- if (withGraphAdd ) {
864
- result = graph .addOrUniqueWithInputs (result );
865
- }
866
- return result ;
867
- }
868
- return readValue ;
854
+ /**
855
+ * Coerce integer values into a boolean 0 or 1 to match Java semantics. The returned nodes have
856
+ * not been added to the graph.
857
+ */
858
+ private static ValueNode performBooleanCoercion (ValueNode readValue ) {
859
+ IntegerEqualsNode eq = new IntegerEqualsNode (readValue , ConstantNode .forInt (0 ));
860
+ return new ConditionalNode (eq , ConstantNode .forBoolean (false ), ConstantNode .forBoolean (true ));
869
861
}
870
862
871
863
protected void lowerUnsafeStoreNode (RawStoreNode store ) {
@@ -1278,39 +1270,49 @@ protected Stamp loadStamp(Stamp stamp, JavaKind kind, boolean compressible) {
1278
1270
return stamp ;
1279
1271
}
1280
1272
1281
- public final ValueNode implicitLoadConvertWithBooleanCoercionIfNecessary (StructuredGraph graph , JavaKind kind , ValueNode value ) {
1282
- return performBooleanCoercionIfNecessary (implicitLoadConvert (graph , kind , value ), kind );
1273
+ protected abstract ValueNode newCompressionNode (CompressionOp op , ValueNode value );
1274
+
1275
+ /**
1276
+ * Perform sign or zero extensions for subword types, and convert potentially unsafe 8 bit
1277
+ * boolean values into 0 or 1. The nodes have already been added to the graph.
1278
+ */
1279
+ public final ValueNode implicitUnsafeLoadConvert (StructuredGraph graph , JavaKind kind , ValueNode value , boolean compressible ) {
1280
+ if (compressible && kind .isObject ()) {
1281
+ return implicitLoadConvert (graph , kind , value , compressible );
1282
+ } else {
1283
+ ValueNode ret = implicitUnsafePrimitiveLoadConvert (kind , value );
1284
+ if (!ret .isAlive ()) {
1285
+ ret = graph .addOrUniqueWithInputs (ret );
1286
+ }
1287
+ return ret ;
1288
+ }
1283
1289
}
1284
1290
1285
1291
public final ValueNode implicitLoadConvert (StructuredGraph graph , JavaKind kind , ValueNode value ) {
1286
1292
return implicitLoadConvert (graph , kind , value , true );
1287
1293
}
1288
1294
1289
- public ValueNode implicitLoadConvert (JavaKind kind , ValueNode value ) {
1290
- return implicitLoadConvert (kind , value , true );
1291
- }
1292
-
1295
+ /**
1296
+ * Perform sign or zero extensions for subword types and add the nodes to the graph.
1297
+ */
1293
1298
protected final ValueNode implicitLoadConvert (StructuredGraph graph , JavaKind kind , ValueNode value , boolean compressible ) {
1294
- ValueNode ret = implicitLoadConvert (kind , value , compressible );
1299
+ ValueNode ret ;
1300
+ if (useCompressedOops (kind , compressible )) {
1301
+ ret = newCompressionNode (CompressionOp .Uncompress , value );
1302
+ } else {
1303
+ ret = implicitPrimitiveLoadConvert (kind , value );
1304
+ }
1305
+
1295
1306
if (!ret .isAlive ()) {
1296
- ret = graph .addOrUnique (ret );
1307
+ ret = graph .addOrUniqueWithInputs (ret );
1297
1308
}
1298
1309
return ret ;
1299
1310
}
1300
1311
1301
- protected abstract ValueNode newCompressionNode (CompressionOp op , ValueNode value );
1302
-
1303
1312
/**
1304
- * @param compressible whether the convert should be compressible
1313
+ * Perform sign or zero extensions for subword types. The caller is expected to add an resulting
1314
+ * nodes to the graph.
1305
1315
*/
1306
- protected ValueNode implicitLoadConvert (JavaKind kind , ValueNode value , boolean compressible ) {
1307
- if (useCompressedOops (kind , compressible )) {
1308
- return newCompressionNode (CompressionOp .Uncompress , value );
1309
- }
1310
-
1311
- return implicitPrimitiveLoadConvert (kind , value );
1312
- }
1313
-
1314
1316
public static ValueNode implicitPrimitiveLoadConvert (JavaKind kind , ValueNode value ) {
1315
1317
return switch (kind ) {
1316
1318
case Byte , Short -> new SignExtendNode (value , 32 );
@@ -1319,6 +1321,17 @@ public static ValueNode implicitPrimitiveLoadConvert(JavaKind kind, ValueNode va
1319
1321
};
1320
1322
}
1321
1323
1324
+ /**
1325
+ * Perform sign or zero extensions for subword types, and convert potentially unsafe 8 bit
1326
+ * boolean values into 0 or 1. The caller is expected to add an resulting * nodes to the graph.
1327
+ */
1328
+ public static ValueNode implicitUnsafePrimitiveLoadConvert (JavaKind kind , ValueNode value ) {
1329
+ if (kind == JavaKind .Boolean ) {
1330
+ return performBooleanCoercion (new ZeroExtendNode (value , 32 ));
1331
+ }
1332
+ return implicitPrimitiveLoadConvert (kind , value );
1333
+ }
1334
+
1322
1335
public ValueNode arrayImplicitStoreConvert (StructuredGraph graph ,
1323
1336
JavaKind entryKind ,
1324
1337
ValueNode value ,
0 commit comments