llvm.org GIT mirror llvm / 7e48926
Merging r326376: ------------------------------------------------------------------------ r326376 | jdevlieghere | 2018-02-28 14:28:44 -0800 (Wed, 28 Feb 2018) | 12 lines [GlobalOpt] don't change CC of musttail calle(e|r) When the function has musttail call - its cc is fixed to be equal to the cc of the musttail callee. In such case (and in the case of the musttail callee), GlobalOpt should not change the cc to fastcc as it will break the invariant. This fixes PR36546 Patch by: Fedor Indutny (indutny) Differential revision: https://reviews.llvm.org/D43859 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@329634 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 5 months ago
2 changed file(s) with 58 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
20982098 /// GHC, or anyregcc.
20992099 static bool isProfitableToMakeFastCC(Function *F) {
21002100 CallingConv::ID CC = F->getCallingConv();
2101
21012102 // FIXME: Is it worth transforming x86_stdcallcc and x86_fastcallcc?
2102 return CC == CallingConv::C || CC == CallingConv::X86_ThisCall;
2103 if (CC != CallingConv::C && CC != CallingConv::X86_ThisCall)
2104 return false;
2105
2106 // FIXME: Change CC for the whole chain of musttail calls when possible.
2107 //
2108 // Can't change CC of the function that either has musttail calls, or is a
2109 // musttail callee itself
2110 for (User *U : F->users()) {
2111 if (isa(U))
2112 continue;
2113 CallInst* CI = dyn_cast(U);
2114 if (!CI)
2115 continue;
2116
2117 if (CI->isMustTailCall())
2118 return false;
2119 }
2120
2121 for (BasicBlock &BB : *F)
2122 if (BB.getTerminatingMustTailCall())
2123 return false;
2124
2125 return true;
21032126 }
21042127
21052128 static bool
0 ; RUN: opt < %s -globalopt -S | FileCheck %s
1 ; PR36546
2
3 ; Check that musttail callee preserves its calling convention
4
5 define i32 @test(i32 %a) {
6 ; CHECK: %ca = musttail call i32 @foo(i32 %a)
7 %ca = musttail call i32 @foo(i32 %a)
8 ret i32 %ca
9 }
10
11 ; CHECK-LABEL: define internal i32 @foo(i32 %a)
12 define internal i32 @foo(i32 %a) {
13 ret i32 %a
14 }
15
16 ; Check that musttail caller preserves its calling convention
17
18 define i32 @test2(i32 %a) {
19 %ca = call i32 @foo1(i32 %a)
20 ret i32 %ca
21 }
22
23 ; CHECK-LABEL: define internal i32 @foo1(i32 %a)
24 define internal i32 @foo1(i32 %a) {
25 ; CHECK: %ca = musttail call i32 @foo2(i32 %a)
26 %ca = musttail call i32 @foo2(i32 %a)
27 ret i32 %ca
28 }
29
30 ; CHECK-LABEL: define internal i32 @foo2(i32 %a)
31 define internal i32 @foo2(i32 %a) {
32 ret i32 %a
33 }