Skip to content

Commit 0a07e6b

Browse files
authored
[llvm] Allow Fast and Tail CC in UEFI (#138361)
Allow tail call and fastcc optimizations for UEFI X86_64 targets.
1 parent aa77f7a commit 0a07e6b

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ class X86Subtarget final : public X86GenSubtargetInfo {
350350
switch (CC) {
351351
// On Win64, all these conventions just use the default convention.
352352
case CallingConv::C:
353-
return isTargetWin64() || isTargetUEFI64();
354353
case CallingConv::Fast:
355354
case CallingConv::Tail:
355+
return isTargetWin64() || isTargetUEFI64();
356356
case CallingConv::Swift:
357357
case CallingConv::SwiftTail:
358358
case CallingConv::X86_FastCall:

llvm/test/CodeGen/X86/musttail-tailcc.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s -check-prefix=X64
3+
; RUN: llc < %s -mtriple=x86_64-uefi | FileCheck %s -check-prefix=X64
34
; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s -check-prefix=X32
45

56
; tailcc will turn all of these musttail calls into tail calls.

llvm/test/CodeGen/X86/tailcall-tailcc.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s -check-prefix=X64
3+
; RUN: llc < %s -mtriple=x86_64-windows-msvc | FileCheck %s -check-prefix=UEFI64
4+
; RUN: llc < %s -mtriple=x86_64-uefi | FileCheck %s -check-prefix=UEFI64
35
; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s -check-prefix=X32
46

57
; With -tailcallopt, CodeGen guarantees a tail call optimization
@@ -16,6 +18,14 @@ define dso_local tailcc i32 @tailcaller(i32 %in1, i32 %in2) nounwind {
1618
; X64-NEXT: popq %rax
1719
; X64-NEXT: jmp tailcallee # TAILCALL
1820
;
21+
; UEFI64-LABEL: tailcaller:
22+
; UEFI64: # %bb.0: # %entry
23+
; UEFI64-NEXT: subq $40, %rsp
24+
; UEFI64-NEXT: movl %ecx, %r8d
25+
; UEFI64-NEXT: movl %edx, %r9d
26+
; UEFI64-NEXT: addq $40, %rsp
27+
; UEFI64-NEXT: jmp tailcallee # TAILCALL
28+
;
1929
; X32-LABEL: tailcaller:
2030
; X32: # %bb.0: # %entry
2131
; X32-NEXT: subl $16, %esp
@@ -39,6 +49,10 @@ define tailcc noalias ptr @noalias_caller() nounwind {
3949
; X64-NEXT: popq %rax
4050
; X64-NEXT: jmp alias_callee # TAILCALL
4151
;
52+
; UEFI64-LABEL: noalias_caller:
53+
; UEFI64: # %bb.0:
54+
; UEFI64-NEXT: jmp alias_callee # TAILCALL
55+
;
4256
; X32-LABEL: noalias_caller:
4357
; X32: # %bb.0:
4458
; X32-NEXT: jmp alias_callee # TAILCALL
@@ -55,6 +69,10 @@ define dso_local tailcc ptr @alias_caller() nounwind {
5569
; X64-NEXT: popq %rax
5670
; X64-NEXT: jmp noalias_callee # TAILCALL
5771
;
72+
; UEFI64-LABEL: alias_caller:
73+
; UEFI64: # %bb.0:
74+
; UEFI64-NEXT: jmp noalias_callee # TAILCALL
75+
;
5876
; X32-LABEL: alias_caller:
5977
; X32: # %bb.0:
6078
; X32-NEXT: jmp noalias_callee # TAILCALL
@@ -71,6 +89,10 @@ define dso_local tailcc i32 @ret_undef() nounwind {
7189
; X64-NEXT: popq %rax
7290
; X64-NEXT: jmp i32_callee # TAILCALL
7391
;
92+
; UEFI64-LABEL: ret_undef:
93+
; UEFI64: # %bb.0:
94+
; UEFI64-NEXT: jmp i32_callee # TAILCALL
95+
;
7496
; X32-LABEL: ret_undef:
7597
; X32: # %bb.0:
7698
; X32-NEXT: jmp i32_callee # TAILCALL
@@ -87,6 +109,10 @@ define dso_local tailcc i32 @noret() nounwind {
87109
; X64-NEXT: popq %rax
88110
; X64-NEXT: jmp does_not_return # TAILCALL
89111
;
112+
; UEFI64-LABEL: noret:
113+
; UEFI64: # %bb.0:
114+
; UEFI64-NEXT: jmp does_not_return # TAILCALL
115+
;
90116
; X32-LABEL: noret:
91117
; X32: # %bb.0:
92118
; X32-NEXT: jmp does_not_return # TAILCALL
@@ -103,6 +129,16 @@ define dso_local tailcc void @void_test(i32, i32, i32, i32) {
103129
; X64-NEXT: .cfi_def_cfa_offset 8
104130
; X64-NEXT: jmp void_test # TAILCALL
105131
;
132+
; UEFI64-LABEL: void_test:
133+
; UEFI64: # %bb.0: # %entry
134+
; UEFI64-NEXT: subq $40, %rsp
135+
; UEFI64-NEXT: .seh_stackalloc 40
136+
; UEFI64-NEXT: .seh_endprologue
137+
; UEFI64-NEXT: .seh_startepilogue
138+
; UEFI64-NEXT: addq $40, %rsp
139+
; UEFI64-NEXT: .seh_endepilogue
140+
; UEFI64-NEXT: jmp void_test # TAILCALL
141+
;
106142
; X32-LABEL: void_test:
107143
; X32: # %bb.0: # %entry
108144
; X32-NEXT: pushl %esi
@@ -133,6 +169,16 @@ define dso_local tailcc i1 @i1test(i32, i32, i32, i32) {
133169
; X64-NEXT: .cfi_def_cfa_offset 8
134170
; X64-NEXT: jmp i1test # TAILCALL
135171
;
172+
; UEFI64-LABEL: i1test:
173+
; UEFI64: # %bb.0: # %entry
174+
; UEFI64-NEXT: subq $40, %rsp
175+
; UEFI64-NEXT: .seh_stackalloc 40
176+
; UEFI64-NEXT: .seh_endprologue
177+
; UEFI64-NEXT: .seh_startepilogue
178+
; UEFI64-NEXT: addq $40, %rsp
179+
; UEFI64-NEXT: .seh_endepilogue
180+
; UEFI64-NEXT: jmp i1test # TAILCALL
181+
;
136182
; X32-LABEL: i1test:
137183
; X32: # %bb.0: # %entry
138184
; X32-NEXT: pushl %esi

llvm/test/CodeGen/X86/tailcc-fastcc.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc -tailcallopt < %s -mtriple=x86_64-unknown-unknown | FileCheck %s -check-prefix=X64
3+
; RUN: llc -tailcallopt < %s -mtriple=x86_64-uefi | FileCheck %s -check-prefix=UEFI64
34
; RUN: llc -tailcallopt < %s -mtriple=i686-unknown-unknown | FileCheck %s -check-prefix=X32
45

56
; llc -tailcallopt should not enable tail calls from fastcc to tailcc or vice versa
@@ -15,6 +16,14 @@ define fastcc i32 @tailcaller1(i32 %in1, i32 %in2) nounwind {
1516
; X64-NEXT: callq tailcallee1@PLT
1617
; X64-NEXT: retq $8
1718
;
19+
; UEFI64-LABEL: tailcaller1:
20+
; UEFI64: # %bb.0: # %entry
21+
; UEFI64-NEXT: subq $40, %rsp
22+
; UEFI64-NEXT: movl %ecx, %r8d
23+
; UEFI64-NEXT: movl %edx, %r9d
24+
; UEFI64-NEXT: callq tailcallee1
25+
; UEFI64-NEXT: retq $40
26+
;
1827
; X32-LABEL: tailcaller1:
1928
; X32: # %bb.0: # %entry
2029
; X32-NEXT: pushl %edx
@@ -37,6 +46,14 @@ define tailcc i32 @tailcaller2(i32 %in1, i32 %in2) nounwind {
3746
; X64-NEXT: callq tailcallee2@PLT
3847
; X64-NEXT: retq $8
3948
;
49+
; UEFI64-LABEL: tailcaller2:
50+
; UEFI64: # %bb.0: # %entry
51+
; UEFI64-NEXT: subq $40, %rsp
52+
; UEFI64-NEXT: movl %ecx, %r8d
53+
; UEFI64-NEXT: movl %edx, %r9d
54+
; UEFI64-NEXT: callq tailcallee2
55+
; UEFI64-NEXT: retq $40
56+
;
4057
; X32-LABEL: tailcaller2:
4158
; X32: # %bb.0: # %entry
4259
; X32-NEXT: pushl %edx

llvm/test/CodeGen/X86/tailcc-fastisel.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -fast-isel -fast-isel-abort=1 | FileCheck %s
1+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -fast-isel -fast-isel-abort=1 | FileCheck %s -check-prefix=DARWIN64
2+
; RUN: llc < %s -mtriple=x86_64-uefi -fast-isel -fast-isel-abort=1 | FileCheck %s -check-prefix=UEFI64
23

34
%0 = type { i64, i32, ptr }
45

56
define tailcc ptr @"visit_array_aux<`Reference>"(%0 %arg, i32 %arg1) nounwind {
67
fail: ; preds = %entry
78
%tmp20 = tail call tailcc ptr @"visit_array_aux<`Reference>"(%0 %arg, i32 undef) ; <ptr> [#uses=1]
8-
; CHECK: jmp "_visit_array_aux<`Reference>" ## TAILCALL
9+
; DARWIN64: jmp "_visit_array_aux<`Reference>" ## TAILCALL
10+
; UEFI64: jmp "visit_array_aux<`Reference>" # TAILCALL
911
ret ptr %tmp20
1012
}
1113

llvm/test/CodeGen/X86/tailccstack64.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux -post-RA-scheduler=true | FileCheck %s
22
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-win32 -post-RA-scheduler=true | FileCheck %s
3+
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-uefi -post-RA-scheduler=true | FileCheck %s
34

45
; FIXME: Redundant unused stack allocation could be eliminated.
56
; CHECK: subq ${{24|72|80}}, %rsp

llvm/test/CodeGen/X86/uefi-fastcc.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc < %s -mtriple=x86_64-uefi | FileCheck %s -check-prefix=UEFIFAST64
2+
; RUN: llc < %s -mtriple=x86_64-windows-msvc | FileCheck %s -check-prefix=UEFIFAST64
3+
4+
declare fastcc i32 @fastcallee1(i32 %a1, i32 %a2, i32 %a3, i32 %a4)
5+
6+
define fastcc i32 @fastcaller1(i32 %in1, i32 %in2) nounwind {
7+
;; Test that the caller allocates stack space for callee to spill the register arguments.
8+
; UEFIFAST64-LABEL: fastcaller1:
9+
; UEFIFAST64: # %bb.0: # %entry
10+
; UEFIFAST64-NEXT: subq $40, %rsp
11+
; UEFIFAST64-NEXT: movl %ecx, %r8d
12+
; UEFIFAST64-NEXT: movl %edx, %r9d
13+
; UEFIFAST64-NEXT: callq fastcallee1
14+
; UEFIFAST64-NEXT: addq $40, %rsp
15+
; UEFIFAST64-NEXT: retq
16+
entry:
17+
%tmp11 = call fastcc i32 @fastcallee1(i32 %in1, i32 %in2, i32 %in1, i32 %in2)
18+
ret i32 %tmp11
19+
}

0 commit comments

Comments
 (0)