Skip to content

Commit 613de14

Browse files
committed
Backup only the lower 128bits of the XMM callee save registers on Windows
1 parent e77a7dc commit 613de14

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/lir/alloc/SaveCalleeSaveRegisters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ private static RegisterMap<AllocatableValue> saveAtEntry(LIR lir, LIRGeneratorTo
8080
List<Register> allocatables = lirGenRes.getRegisterConfig().getAllocatableRegisters().asList();
8181
RegisterMap<AllocatableValue> saveMap = new RegisterMap<>(arch);
8282
for (Register register : calleeSaveRegisters) {
83-
PlatformKind registerPlatformKind = arch.getLargestStorableKind(register.getRegisterCategory());
83+
PlatformKind registerPlatformKind = lirGenRes.getRegisterConfig().getCalleeSaveRegisterStorageKind(arch, register);
8484
LIRKind lirKind = LIRKind.value(registerPlatformKind);
8585
RegisterValue registerValue = register.asValue(lirKind);
86+
// Force a non-allocatable register to be saved to a stack slot
87+
// so as to avoid unnecessary register pressure.
8688
AllocatableValue saveVariable = allocatables.contains(registerValue.getRegister()) ? lirGen.newVariable(lirKind) : lirGenRes.getFrameMapBuilder().allocateSpillSlot(lirKind);
8789
LIRInstruction save = lirGen.getSpillMoveFactory().createMove(saveVariable, registerValue);
8890
buffer.append(insertionIndex, save);

substratevm/src/com.oracle.svm.core.graal.amd64/src/com/oracle/svm/core/graal/amd64/SubstrateAMD64RegisterConfig.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 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
@@ -63,6 +63,7 @@
6363
import static jdk.vm.ci.amd64.AMD64.xmm7;
6464
import static jdk.vm.ci.amd64.AMD64.xmm8;
6565
import static jdk.vm.ci.amd64.AMD64.xmm9;
66+
import static jdk.vm.ci.amd64.AMD64Kind.V128_QWORD;
6667

6768
import java.util.ArrayList;
6869
import java.util.Arrays;
@@ -85,6 +86,7 @@
8586
import jdk.graal.compiler.core.common.LIRKind;
8687
import jdk.vm.ci.amd64.AMD64;
8788
import jdk.vm.ci.amd64.AMD64Kind;
89+
import jdk.vm.ci.code.Architecture;
8890
import jdk.vm.ci.code.CallingConvention;
8991
import jdk.vm.ci.code.CallingConvention.Type;
9092
import jdk.vm.ci.code.Register;
@@ -236,6 +238,15 @@ public RegisterArray getCalleeSaveRegisters() {
236238
return calleeSaveRegisters;
237239
}
238240

241+
@Override
242+
public PlatformKind getCalleeSaveRegisterStorageKind(Architecture arch, Register calleeSaveRegister) {
243+
if (Platform.includedIn(Platform.WINDOWS.class) && AMD64.XMM.equals(calleeSaveRegister.getRegisterCategory())) {
244+
VMError.guarantee(calleeSaveRegister.encoding() >= xmm6.encoding() && calleeSaveRegister.encoding() <= xmm15.encoding(), "unexpected callee saved register %s", calleeSaveRegister);
245+
return V128_QWORD;
246+
}
247+
return SubstrateRegisterConfig.super.getCalleeSaveRegisterStorageKind(arch, calleeSaveRegister);
248+
}
249+
239250
@Override
240251
public RegisterArray getCallerSaveRegisters() {
241252
return getAllocatableRegisters();
@@ -407,7 +418,7 @@ public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaT
407418
kinds = Arrays.copyOf(kinds, kinds.length + 1);
408419
locations = Arrays.copyOf(locations, locations.length + 1);
409420
kinds[kinds.length - 1] = JavaKind.Int;
410-
locations[locations.length - 1] = AMD64.rax.asValue(LIRKind.value(AMD64Kind.DWORD));
421+
locations[locations.length - 1] = rax.asValue(LIRKind.value(AMD64Kind.DWORD));
411422
if (type.customABI()) {
412423
var extendsParametersAssignment = Arrays.copyOf(type.fixedParameterAssignment, type.fixedParameterAssignment.length + 1);
413424
extendsParametersAssignment[extendsParametersAssignment.length - 1] = AssignedLocation.forRegister(rax, JavaKind.Long);

0 commit comments

Comments
 (0)