Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1406573

Browse files
committed
[X86] Disable shrink-wrapping for tailcc/swifttailcc functions.
Pseudo-expansion's handling of tail-calls currently interacts badly with shrink-wrapping when using callee-pop CCs on x86_64, resulting in an unbalanced RSP adjustment on shrink-wrapped return paths. Disable shrink-wrapping until that's resolved, if it can be. See llvm#109279 rdar://141673907
1 parent 2653f72 commit 1406573

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

llvm/lib/Target/X86/X86FrameLowering.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3942,6 +3942,14 @@ bool X86FrameLowering::canUseAsEpilogue(const MachineBasicBlock &MBB) const {
39423942
}
39433943

39443944
bool X86FrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
3945+
// Pseudo-expansion's handling of tail-calls currently interacts badly
3946+
// with shrink-wrapping when using callee-pop CCs on x86_64.
3947+
// Disable shrink-wrapping until that's resolved, if it can be.
3948+
// See llvm issue 109279.
3949+
CallingConv::ID CC = MF.getFunction().getCallingConv();
3950+
if (CC == CallingConv::Tail || CC == CallingConv::SwiftTail)
3951+
return false;
3952+
39453953
// If we may need to emit frameless compact unwind information, give
39463954
// up as this is currently broken: PR25614.
39473955
bool CompactUnwind =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -o - < %s | FileCheck %s
3+
4+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5+
target triple = "x86_64-apple-macosx"
6+
7+
; Pseudo-expansion's handling of tail-calls currently interacts badly
8+
; with shrink-wrapping when using callee-pop CCs on x86_64, resulting
9+
; in an unbalanced RSP adjustment on shrink-wrapped return paths.
10+
11+
; Make sure it's disabled today until that's resolved.
12+
13+
; See https://github.com/llvm/llvm-project/issues/109279
14+
15+
define tailcc void @test_shrink_wrap_tailcc(i64 %0) {
16+
; CHECK-LABEL: test_shrink_wrap_tailcc:
17+
; CHECK: ## %bb.0:
18+
; CHECK-NEXT: subq $32, %rsp
19+
; CHECK-NEXT: .cfi_def_cfa_offset 40
20+
; CHECK-NEXT: testq %rdi, %rdi
21+
; CHECK-NEXT: je LBB0_2
22+
; CHECK-NEXT: ## %bb.1: ## %a
23+
; CHECK-NEXT: xorps %xmm0, %xmm0
24+
; CHECK-NEXT: movaps %xmm0, {{[0-9]+}}(%rsp)
25+
; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rax
26+
; CHECK-NEXT: movaps %xmm0, {{[0-9]+}}(%rsp)
27+
; CHECK-NEXT: movq %rax, (%rsp)
28+
; CHECK-NEXT: movl $16, %esi
29+
; CHECK-NEXT: xorl %edi, %edi
30+
; CHECK-NEXT: xorl %edx, %edx
31+
; CHECK-NEXT: movl $1, %ecx
32+
; CHECK-NEXT: xorl %r8d, %r8d
33+
; CHECK-NEXT: xorl %r9d, %r9d
34+
; CHECK-NEXT: jmp _f1 ## TAILCALL
35+
; CHECK-NEXT: LBB0_2: ## %b
36+
; CHECK-NEXT: addq $32, %rsp
37+
; CHECK-NEXT: jmp _f2 ## TAILCALL
38+
%cond = icmp ugt i64 %0, 0
39+
br i1 %cond, label %a, label %b
40+
a:
41+
musttail call tailcc void @f1(ptr null, i64 16, ptr null, i8 1, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null)
42+
ret void
43+
b:
44+
musttail call tailcc void @f2()
45+
ret void
46+
}
47+
48+
declare tailcc void @f2()
49+
declare tailcc void @f1(ptr, i64, ptr, i8, ptr, ptr, ptr, ptr, ptr, ptr)
50+
51+
define tailcc void @test_shrink_wrap_swifttailcc(i64 %0) {
52+
; CHECK-LABEL: test_shrink_wrap_swifttailcc:
53+
; CHECK: ## %bb.0:
54+
; CHECK-NEXT: subq $32, %rsp
55+
; CHECK-NEXT: .cfi_def_cfa_offset 40
56+
; CHECK-NEXT: testq %rdi, %rdi
57+
; CHECK-NEXT: je LBB1_2
58+
; CHECK-NEXT: ## %bb.1: ## %a
59+
; CHECK-NEXT: xorps %xmm0, %xmm0
60+
; CHECK-NEXT: movaps %xmm0, {{[0-9]+}}(%rsp)
61+
; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rax
62+
; CHECK-NEXT: movaps %xmm0, {{[0-9]+}}(%rsp)
63+
; CHECK-NEXT: movq %rax, (%rsp)
64+
; CHECK-NEXT: movl $16, %esi
65+
; CHECK-NEXT: xorl %edi, %edi
66+
; CHECK-NEXT: xorl %edx, %edx
67+
; CHECK-NEXT: movl $1, %ecx
68+
; CHECK-NEXT: xorl %r8d, %r8d
69+
; CHECK-NEXT: xorl %r9d, %r9d
70+
; CHECK-NEXT: jmp _sf1 ## TAILCALL
71+
; CHECK-NEXT: LBB1_2: ## %b
72+
; CHECK-NEXT: addq $32, %rsp
73+
; CHECK-NEXT: jmp _sf2 ## TAILCALL
74+
%cond = icmp ugt i64 %0, 0
75+
br i1 %cond, label %a, label %b
76+
a:
77+
musttail call tailcc void @sf1(ptr null, i64 16, ptr null, i8 1, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null)
78+
ret void
79+
b:
80+
musttail call tailcc void @sf2()
81+
ret void
82+
}
83+
84+
declare tailcc void @sf2()
85+
declare tailcc void @sf1(ptr, i64, ptr, i8, ptr, ptr, ptr, ptr, ptr, ptr)

0 commit comments

Comments
 (0)