llvm.org GIT mirror llvm / ad4af60
[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/trunk@326376 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 2 years ago
2 changed file(s) with 58 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
21142114 /// GHC, or anyregcc.
21152115 static bool hasChangeableCC(Function *F) {
21162116 CallingConv::ID CC = F->getCallingConv();
2117
21172118 // FIXME: Is it worth transforming x86_stdcallcc and x86_fastcallcc?
2118 return CC == CallingConv::C || CC == CallingConv::X86_ThisCall;
2119 if (CC != CallingConv::C && CC != CallingConv::X86_ThisCall)
2120 return false;
2121
2122 // FIXME: Change CC for the whole chain of musttail calls when possible.
2123 //
2124 // Can't change CC of the function that either has musttail calls, or is a
2125 // musttail callee itself
2126 for (User *U : F->users()) {
2127 if (isa(U))
2128 continue;
2129 CallInst* CI = dyn_cast(U);
2130 if (!CI)
2131 continue;
2132
2133 if (CI->isMustTailCall())
2134 return false;
2135 }
2136
2137 for (BasicBlock &BB : *F)
2138 if (BB.getTerminatingMustTailCall())
2139 return false;
2140
2141 return true;
21192142 }
21202143
21212144 /// Return true if the block containing the call site has a BlockFrequency of
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 }