Skip to content

Commit 78745ed

Browse files
committed
fix more langref mistakes with aarch64 calling convention
The calling convention previously stated that X9 and X15 were callee-preserved, but the implementation of AArch64FrameLowering.cpp uses those as scratch registers and does not actually preserve it.
1 parent 9aa0553 commit 78745ed

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

llvm/docs/LangRef.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ added in the future:
410410
calling convention: on most platforms, they are not preserved and need to
411411
be saved by the caller, but on Windows, xmm6-xmm15 are preserved.
412412

413-
- On AArch64 the callee preserve all general purpose registers, except X0-X8
414-
and X16-X18.
413+
- On AArch64 the callee preserve all general purpose registers, except X0-X9
414+
and X15-X18. X9 can be used as a scratch register.
415415

416416
The idea behind this convention is to support calls to runtime functions
417417
that have a hot path and a cold path. The hot path is usually a small piece
@@ -447,9 +447,9 @@ added in the future:
447447
R11. R11 can be used as a scratch register. Furthermore it also preserves
448448
all floating-point registers (XMMs/YMMs).
449449

450-
- On AArch64 the callee preserve all general purpose registers, except X0-X8
451-
and X16-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD -
452-
floating point registers.
450+
- On AArch64 the callee preserve all general purpose registers, except X0-X9
451+
and X15-X18. Furthermore it also preserves lower 128 bits of V8-V31 SIMD -
452+
floating point registers. X9 can be used as a scratch register.
453453

454454
The idea behind this convention is to support calls to runtime functions
455455
that don't need to call out to any other functions.

llvm/lib/Target/AArch64/AArch64CallingConvention.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def CSR_AArch64_NoRegs : CalleeSavedRegs<(add)>;
691691
def CSR_AArch64_NoneRegs : CalleeSavedRegs<(add LR, FP)>;
692692

693693
def CSR_AArch64_RT_MostRegs : CalleeSavedRegs<(add CSR_AArch64_AAPCS,
694-
(sequence "X%u", 9, 15))>;
694+
(sequence "X%u", 10, 14))>;
695695

696696
def CSR_AArch64_RT_AllRegs : CalleeSavedRegs<(add CSR_AArch64_RT_MostRegs,
697697
(sequence "Q%u", 8, 31))>;

llvm/test/CodeGen/AArch64/arm64-preserve-all.ll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ target triple = "aarch64-unknown-linux-gnu"
77
declare void @normal_cc()
88

99
; Caller: preserve_allcc; callee: normalcc. Normally callee saved registers
10-
; x9~x15 need to be spilled. Since most of them will be spilled in pairs in
11-
; reverse order, we only check the odd number ones due to FileCheck not
10+
; x10~x14 need to be spilled. Since most of them will be spilled in pairs in
11+
; reverse order, we only check the even number ones due to FileCheck not
1212
; matching the same line of assembly twice.
1313
; CHECK-LABEL: preserve_all
1414
; CHECK-DAG: {{st[rp]}} {{(q[0-9]+, )?q8(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
@@ -22,21 +22,23 @@ declare void @normal_cc()
2222
; CHECK-DAG: {{st[rp]}} {{(q[0-9]+, )?q26(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
2323
; CHECK-DAG: {{st[rp]}} {{(q[0-9]+, )?q28(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
2424
; CHECK-DAG: {{st[rp]}} {{(q[0-9]+, )?q30(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
25-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x9(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
26-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x11(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
27-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x13(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
28-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x15(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
25+
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x10(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
26+
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x12(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
27+
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x14(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
2928
define preserve_allcc void @preserve_all() {
3029
call void @normal_cc()
3130
ret void
3231
}
3332

3433
; Caller: normalcc; callee: preserve_allcc. x9/q9 does not need to be spilled.
35-
; The same holds for other x and q registers, but we only check x9 and q9.
34+
; The same holds for other x and q registers, but we only check x9, x11, and q9.
3635
; CHECK-LABEL: normal_cc_caller
3736
; CHECK-NOT: stp {{x[0-9]+}}, x9, [sp, #{{[-0-9]+}}]
3837
; CHECK-NOT: stp x9, {{x[0-9]+}}, [sp, #{{[-0-9]+}}]
3938
; CHECK-NOT: str x9, [sp, {{#[-0-9]+}}]
39+
; CHECK-NOT: stp {{x[0-9]+}}, x11, [sp, #{{[-0-9]+}}]
40+
; CHECK-NOT: stp x10, {{x[0-9]+}}, [sp, #{{[-0-9]+}}]
41+
; CHECK-NOT: str x10, [sp, {{#[-0-9]+}}]
4042
; CHECK-NOT: stp {{q[0-9]+}}, q9, [sp, #{{[-0-9]+}}]
4143
; CHECK-NOT: stp q9, {{q[0-9]+}}, [sp, #{{[-0-9]+}}]
4244
; CHECK-NOT: str q9, [sp, {{#[-0-9]+}}]

llvm/test/CodeGen/AArch64/arm64-preserve-most.ll

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@ target triple = "aarch64-unknown-linux-gnu"
77
declare void @normal_cc()
88

99
; Caller: preserve_mostcc; callee: normalcc. Normally callee saved registers
10-
; x9~x15 need to be spilled. Since most of them will be spilled in pairs in
11-
; reverse order, we only check the odd number ones due to FileCheck not
10+
; x10~x14 need to be spilled. Since most of them will be spilled in pairs in
11+
; reverse order, we only check the even number ones due to FileCheck not
1212
; matching the same line of assembly twice.
1313
; CHECK-LABEL: preserve_most
14-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x9(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
15-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x11(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
16-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x13(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
17-
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x15(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
14+
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x10(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
15+
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x12(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
16+
; CHECK-DAG: {{st[rp]}} {{(x[0-9]+, )?x14(, x[0-9]+)?}}, [sp, #{{[-0-9]+}}]
1817
define preserve_mostcc void @preserve_most() {
1918
call void @normal_cc()
2019
ret void
2120
}
2221

23-
; Caller: normalcc; callee: preserve_mostcc. x9 does not need to be spilled.
24-
; The same holds for x10 through x15, but we only check x9.
22+
; Caller: normalcc; callee: preserve_mostcc. x9 does need to be spilled, but not x10 to x14.
23+
; (we only check x10).
2524
; CHECK-LABEL: normal_cc_caller
26-
; CHECK-NOT: stp {{x[0-9]+}}, x9, [sp, #{{[-0-9]+}}]
27-
; CHECK-NOT: stp x9, {{x[0-9]+}}, [sp, #{{[-0-9]+}}]
28-
; CHECK-NOT: str x9, [sp, {{#[-0-9]+}}]
25+
; CHECK-NOT: stp {{x[0-9]+}}, x10, [sp, #{{[-0-9]+}}]
26+
; CHECK-NOT: stp x10, {{x[0-9]+}}, [sp, #{{[-0-9]+}}]
27+
; CHECK-NOT: str x10, [sp, {{#[-0-9]+}}]
2928
define dso_local void @normal_cc_caller() {
3029
entry:
3130
%v = alloca i32, align 4

0 commit comments

Comments
 (0)