Skip to content

Commit a84fa98

Browse files
committed
arm64: don't save vaargs regs if there is no va_start
1 parent 2cd8207 commit a84fa98

File tree

7 files changed

+22
-36
lines changed

7 files changed

+22
-36
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8189,7 +8189,7 @@ SDValue AArch64TargetLowering::LowerFormalArguments(
81898189
}
81908190

81918191
// varargs
8192-
if (isVarArg) {
8192+
if (isVarArg && DAG.getMachineFunction().getFrameInfo().hasVAStart()) {
81938193
if (!Subtarget->isTargetDarwin() || IsWin64) {
81948194
// The AAPCS variadic function ABI is identical to the non-variadic
81958195
// one. As a result there may be more arguments in registers and we should

llvm/test/CodeGen/AArch64/GlobalISel/aapcs_vararg_frame.ll

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,12 @@
33
; RUN: llc < %s --global-isel=1 -mtriple=aarch64-linux-gnu -mattr=+fp-armv8 | FileCheck %s --check-prefix=GISEL
44

55
define void @va(i32 %count, half %f, ...) nounwind {
6-
; CHECK-LABEL: va:
7-
; CHECK: // %bb.0: // %entry
8-
; CHECK-NEXT: sub sp, sp, #176
9-
; CHECK-NEXT: stp x2, x3, [sp, #128]
10-
; CHECK-NEXT: str x1, [sp, #120]
11-
; CHECK-NEXT: stp x4, x5, [sp, #144]
12-
; CHECK-NEXT: stp x6, x7, [sp, #160]
13-
; CHECK-NEXT: stp q1, q2, [sp]
14-
; CHECK-NEXT: stp q3, q4, [sp, #32]
15-
; CHECK-NEXT: stp q5, q6, [sp, #64]
16-
; CHECK-NEXT: str q7, [sp, #96]
17-
; CHECK-NEXT: add sp, sp, #176
6+
; CHECK-LABEL: va: // @va
7+
; CHECK: // %bb.0: // %entry
188
; CHECK-NEXT: ret
199
;
20-
; GISEL-LABEL: va:
21-
; GISEL: // %bb.0: // %entry
10+
; GISEL-LABEL: va: // @va
11+
; GISEL: // %bb.0: // %entry
2212
; GISEL-NEXT: sub sp, sp, #176
2313
; GISEL-NEXT: stp x1, x2, [sp, #120]
2414
; GISEL-NEXT: stp x3, x4, [sp, #136]

llvm/test/CodeGen/AArch64/alloca.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,22 @@ define void @test_variadic_alloca(i64 %n, ...) {
8282
; [...]
8383
; CHECK-DAG: stp q0, q1, [x29, #-192]
8484

85-
; CHECK-DAG: stp x5, x6, [x29, #-24]
85+
; CHECK-DAG: stp x5, x6, [x29, #-32]
8686
; [...]
87-
; CHECK-DAG: stp x1, x2, [x29, #-56]
87+
; CHECK-DAG: stp x1, x2, [x29, #-64]
8888

8989
; CHECK-NOFP-ARM64: stp x29, x30, [sp, #-16]!
9090
; CHECK-NOFP-ARM64: mov x29, sp
9191
; CHECK-NOFP-ARM64: sub sp, sp, #64
92-
; CHECK-NOFP-ARM64-DAG: stp x5, x6, [x29, #-24]
92+
; CHECK-NOFP-ARM64-DAG: stp x5, x6, [x29, #-32]
9393
; [...]
94-
; CHECK-NOFP-ARM64-DAG: stp x3, x4, [x29, #-40]
94+
; CHECK-NOFP-ARM64-DAG: stp x3, x4, [x29, #-48]
9595
; [...]
96-
; CHECK-NOFP-ARM64-DAG: stp x1, x2, [x29, #-56]
96+
; CHECK-NOFP-ARM64-DAG: stp x1, x2, [x29, #-64]
9797
; [...]
9898
; CHECK-NOFP-ARM64: mov x8, sp
99-
99+
%valist = alloca i8
100+
call void @llvm.va_start(ptr %valist)
100101
%addr = alloca i8, i64 %n
101102

102103
call void @use_addr(ptr %addr)

llvm/test/CodeGen/AArch64/arm64ec-hybrid-patchable.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ define void @has_varargs(...) hybrid_patchable nounwind {
2424
; CHECK-NEXT: .p2align 2
2525
; CHECK-NEXT: "#has_varargs$hp_target": // @"#has_varargs$hp_target"
2626
; CHECK-NEXT: // %bb.0:
27-
; CHECK-NEXT: sub sp, sp, #32
28-
; CHECK-NEXT: stp x0, x1, [x4, #-32]
29-
; CHECK-NEXT: stp x2, x3, [x4, #-16]
30-
; CHECK-NEXT: add sp, sp, #32
3127
; CHECK-NEXT: ret
3228
ret void
3329
}

llvm/test/CodeGen/AArch64/darwinpcs-tail.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
; CHECK-LABEL: _tailTest:
99
; CHECK: b __ZN1C3addEPKcz
1010
; CHECK-LABEL: __ZThn8_N1C1fEiiiiiiiiiz:
11-
; CHECK: ldr w9, [sp, #4]
12-
; CHECK: str w9, [sp, #4]
11+
; CHECK: ldr w8, [sp, #4]
12+
; CHECK: str w8, [sp, #4]
1313
; CHECK: b __ZN1C1fEiiiiiiiiiz
1414

1515
%class.C = type { %class.A.base, [4 x i8], %class.B.base, [4 x i8] }

llvm/test/CodeGen/AArch64/vararg-tallcall.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ $"??_9B@@$BA@AA" = comdat any
1414
; Function Attrs: noinline optnone
1515
define linkonce_odr void @"??_9B@@$BA@AA"(ptr %this, ...) #1 comdat align 2 {
1616
entry:
17+
%valist = alloca i8
18+
call void @llvm.va_start.p0(ptr %valist)
1719
%this.addr = alloca ptr, align 8
1820
store ptr %this, ptr %this.addr, align 8
1921
%this1 = load ptr, ptr %this.addr, align 8
@@ -37,6 +39,6 @@ attributes #1 = { noinline optnone "thunk" }
3739
; CHECK-EC: ldr x9, [x0]
3840
; CHECK-EC: ldr x11, [x9]
3941
; CHECK-EC: mov v0.16b, v7.16b
40-
; CHECK-EC: add x4, sp, #64
41-
; CHECK-EC: add sp, sp, #64
42+
; CHECK-EC: add x4, sp, #80
43+
; CHECK-EC: add sp, sp, #80
4244
; CHECK-EC: br x11

llvm/test/CodeGen/AArch64/win64_vararg2.ll

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ define i1 @va_func(i32 %a, i8 %b, i8 %c, ...) {
77
; CHECK-LABEL: va_func:
88
; CHECK: .seh_proc va_func
99
; CHECK-NEXT: // %bb.0:
10-
; CHECK-NEXT: sub sp, sp, #80
11-
; CHECK-NEXT: .seh_stackalloc 80
10+
; CHECK-NEXT: sub sp, sp, #32
11+
; CHECK-NEXT: .seh_stackalloc 32
1212
; CHECK-NEXT: str x19, [sp, #16] // 8-byte Folded Spill
1313
; CHECK-NEXT: .seh_save_reg x19, 16
1414
; CHECK-NEXT: str x30, [sp, #24] // 8-byte Folded Spill
1515
; CHECK-NEXT: .seh_save_reg x30, 24
1616
; CHECK-NEXT: .seh_endprologue
1717
; CHECK-NEXT: mov w19, w0
18-
; CHECK-NEXT: stp x3, x4, [sp, #40]
19-
; CHECK-NEXT: stp x5, x6, [sp, #56]
20-
; CHECK-NEXT: str x7, [sp, #72]
2118
; CHECK-NEXT: str w0, [sp, #12]
2219
; CHECK-NEXT: strb w1, [sp, #11]
2320
; CHECK-NEXT: strb w2, [sp, #10]
@@ -29,8 +26,8 @@ define i1 @va_func(i32 %a, i8 %b, i8 %c, ...) {
2926
; CHECK-NEXT: .seh_save_reg x30, 24
3027
; CHECK-NEXT: ldr x19, [sp, #16] // 8-byte Folded Reload
3128
; CHECK-NEXT: .seh_save_reg x19, 16
32-
; CHECK-NEXT: add sp, sp, #80
33-
; CHECK-NEXT: .seh_stackalloc 80
29+
; CHECK-NEXT: add sp, sp, #32
30+
; CHECK-NEXT: .seh_stackalloc 32
3431
; CHECK-NEXT: .seh_endepilogue
3532
; CHECK-NEXT: ret
3633
; CHECK-NEXT: .seh_endfunclet

0 commit comments

Comments
 (0)