Skip to content

Commit dff9bb5

Browse files
committed
[AArch64] Skip over shadow space for ARM64EC entry thunk variadic calls
When in an entry thunk the x64 SP is passed in x4 but this cannot be directly passed through since x64 varargs calls have a 32 byte shadow store at SP followed by the in-stack parameters. ARM64EC varargs calls on the other hand expect x4 to point to the first in-stack parameter.
1 parent 5c84054 commit dff9bb5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8010,7 +8010,17 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
80108010

80118011
if (IsVarArg && Subtarget->isWindowsArm64EC()) {
80128012
SDValue ParamPtr = StackPtr;
8013-
if (IsTailCall) {
8013+
if (MF.getFunction().getCallingConv() == CallingConv::ARM64EC_Thunk_X64) {
8014+
// When in an entry thunk the x64 SP is passed via x4. This cannot
8015+
// be directly passed through since x64 varargs calls have a 32 byte
8016+
// shadow store at SP followed by the in-stack parameters,
8017+
// Arm64EC varargs calls on the other hand expect x4
8018+
// to point to the first in-stack parameter.
8019+
Register VReg = MF.addLiveIn(AArch64::X4, &AArch64::GPR64RegClass);
8020+
SDValue Val = DAG.getCopyFromReg(Chain, DL, VReg, MVT::i64);
8021+
SDValue PtrOff = DAG.getIntPtrConstant(32, DL);
8022+
ParamPtr = DAG.getNode(ISD::ADD, DL, PtrVT, Val, PtrOff);
8023+
} else if (IsTailCall) {
80148024
// Create a dummy object at the top of the stack that can be used to get
80158025
// the SP after the epilogue
80168026
int FI = MF.getFrameInfo().CreateFixedObject(1, FPDiff, true);

llvm/test/CodeGen/AArch64/arm64ec-entry-thunks.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ define void @has_varargs(...) nounwind {
147147
; CHECK-NEXT: add x29, sp, #160
148148
; CHECK-NEXT: .seh_add_fp 160
149149
; CHECK-NEXT: .seh_endprologue
150-
; CHECK-NEXT: mov x4, sp
150+
; CHECK-NEXT: add x4, x4, #32
151151
; CHECK-NEXT: mov x5, xzr
152152
; CHECK-NEXT: blr x9
153153
; CHECK-NEXT: adrp x8, __os_arm64x_dispatch_ret

0 commit comments

Comments
 (0)