Skip to content

Commit f5f9328

Browse files
committed
[GR-63328] Emit additional reinterpret when generating float CAS from node matching rules
PullRequest: graal/20351
2 parents fb43193 + f8a4ca0 commit f5f9328

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/replacements/test/UnsafeReplacementsTest.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,10 @@
2424
*/
2525
package jdk.graal.compiler.replacements.test;
2626

27-
import jdk.graal.compiler.test.AddExports;
2827
import org.junit.Test;
2928

29+
import jdk.graal.compiler.test.AddExports;
30+
3031
@AddExports("java.base/jdk.internal.misc")
3132
public class UnsafeReplacementsTest extends MethodSubstitutionTest {
3233

@@ -155,6 +156,15 @@ public void testCompareAndSet() {
155156
test("unsafeCompareAndSetDouble");
156157
}
157158

159+
public static Boolean unsafeCompareAndSetFloatVar(Container c) {
160+
return unsafe.compareAndSetFloat(c, floatOffset, 1.0f, 2.0f);
161+
}
162+
163+
@Test
164+
public void testUnsafeCompareAndSetFloatVar() {
165+
test("unsafeCompareAndSetFloatVar", new Container());
166+
}
167+
158168
public static boolean unsafeWeakCompareAndSetBoolean() {
159169
Container container = new Container();
160170
boolean success = false;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/amd64/AMD64LIRGenerator.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ private AllocatableValue asAllocatable(Value value, ValueKind<?> kind) {
247247
}
248248
}
249249

250-
private Value emitCompareAndSwap(boolean isLogic, LIRKind accessKind, Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue, BarrierType barrierType) {
250+
private Value emitCompareAndSwapHelper(boolean isLogic, LIRKind accessKind, Value address, Value expectedValue, Value newValue, BarrierType barrierType) {
251251
ValueKind<?> kind = newValue.getValueKind();
252-
assert kind.equals(expectedValue.getValueKind());
252+
GraalError.guarantee(kind.equals(expectedValue.getValueKind()), "%s != %s", kind, expectedValue.getValueKind());
253253

254254
AMD64AddressValue addressValue = asAddressValue(address);
255255
LIRKind integerAccessKind = accessKind;
@@ -270,15 +270,20 @@ private Value emitCompareAndSwap(boolean isLogic, LIRKind accessKind, Value addr
270270
AllocatableValue allocatableNewValue = asAllocatable(reinterpretedNewValue, integerAccessKind);
271271
emitMove(aRes, reinterpretedExpectedValue);
272272
emitCompareAndSwapOp(isLogic, integerAccessKind, memKind, aRes, addressValue, allocatableNewValue, barrierType);
273+
return aRes;
274+
}
275+
276+
private Value emitCompareAndSwap(boolean isLogic, LIRKind accessKind, Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue, BarrierType barrierType) {
277+
Value aRes = emitCompareAndSwapHelper(isLogic, accessKind, address, expectedValue, newValue, barrierType);
273278

274279
if (isLogic) {
275280
assert trueValue.getValueKind().equals(falseValue.getValueKind());
276281
return emitCondMoveOp(Condition.EQ, trueValue, falseValue, false, false);
277282
} else {
278-
if (isXmm) {
283+
if (((AMD64Kind) accessKind.getPlatformKind()).isXMM()) {
279284
return arithmeticLIRGen.emitReinterpret(accessKind, aRes);
280285
} else {
281-
Variable result = newVariable(kind);
286+
Variable result = newVariable(newValue.getValueKind());
282287
emitMove(result, aRes);
283288
return result;
284289
}
@@ -298,13 +303,11 @@ public Value emitValueCompareAndSwap(LIRKind accessKind, Value address, Value ex
298303

299304
public void emitCompareAndSwapBranch(boolean isLogic, LIRKind kind, AMD64AddressValue address, Value expectedValue, Value newValue, Condition condition, LabelRef trueLabel, LabelRef falseLabel,
300305
double trueLabelProbability, BarrierType barrierType) {
301-
assert kind.getPlatformKind().getSizeInBytes() <= expectedValue.getValueKind().getPlatformKind().getSizeInBytes() : kind + " " + expectedValue;
302-
assert kind.getPlatformKind().getSizeInBytes() <= newValue.getValueKind().getPlatformKind().getSizeInBytes() : kind + " " + newValue;
303-
assert condition == Condition.EQ || condition == Condition.NE : Assertions.errorMessage(condition, address, expectedValue, newValue);
304-
AMD64Kind memKind = (AMD64Kind) kind.getPlatformKind();
305-
RegisterValue raxValue = AMD64.rax.asValue(kind);
306-
emitMove(raxValue, expectedValue);
307-
emitCompareAndSwapOp(isLogic, kind, memKind, raxValue, address, asAllocatable(newValue), barrierType);
306+
GraalError.guarantee(kind.getPlatformKind().getSizeInBytes() <= expectedValue.getValueKind().getPlatformKind().getSizeInBytes(), "kind=%s, expectedValue=%s", kind, expectedValue);
307+
GraalError.guarantee(kind.getPlatformKind().getSizeInBytes() <= newValue.getValueKind().getPlatformKind().getSizeInBytes(), "kind=%s, newValue=%s", kind, newValue);
308+
GraalError.guarantee(condition == Condition.EQ || condition == Condition.NE, Assertions.errorMessage(condition, address, expectedValue, newValue));
309+
310+
emitCompareAndSwapHelper(isLogic, kind, address, expectedValue, newValue, barrierType);
308311
append(new BranchOp(condition, trueLabel, falseLabel, trueLabelProbability));
309312
}
310313

0 commit comments

Comments
 (0)