llvm.org GIT mirror llvm / 6842a7c
[ArgumentPromotion] don't break musttail invariant PR36543 Summary: Do not break musttail invariant by promoting arguments of musttail callee or caller. Reviewers: sanjoy, dberlin, hfinkel, george.burgess.iv, fhahn, rnk Reviewed By: rnk Subscribers: rnk, llvm-commits Differential Revision: https://reviews.llvm.org/D43926 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326521 91177308-0d34-0410-b5e6-96231b3b80d8 Fedor Indutny 1 year, 6 months ago
2 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
852852 if (CS.getInstruction() == nullptr || !CS.isCallee(&U))
853853 return nullptr;
854854
855 // Can't change signature of musttail callee
856 if (CS.isMustTailCall())
857 return nullptr;
858
855859 if (CS.getInstruction()->getParent()->getParent() == F)
856860 isSelfRecursive = true;
857861 }
862
863 // Can't change signature of musttail caller
864 // FIXME: Support promoting whole chain of musttail functions
865 for (BasicBlock &BB : *F)
866 if (BB.getTerminatingMustTailCall())
867 return nullptr;
858868
859869 const DataLayout &DL = F->getParent()->getDataLayout();
860870
0 ; RUN: opt < %s -argpromotion -S | FileCheck %s
1 ; PR36543
2
3 ; Don't promote arguments of musttail callee
4
5 %T = type { i32, i32, i32, i32 }
6
7 ; CHECK-LABEL: define internal i32 @test(%T* %p)
8 define internal i32 @test(%T* %p) {
9 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
10 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
11 %a = load i32, i32* %a.gep
12 %b = load i32, i32* %b.gep
13 %v = add i32 %a, %b
14 ret i32 %v
15 }
16
17 ; CHECK-LABEL: define i32 @caller(%T* %p)
18 define i32 @caller(%T* %p) {
19 %v = musttail call i32 @test(%T* %p)
20 ret i32 %v
21 }
22
23 ; Don't promote arguments of musttail caller
24
25 define i32 @foo(%T* %p, i32 %v) {
26 ret i32 0
27 }
28
29 ; CHECK-LABEL: define internal i32 @test2(%T* %p, i32 %p2)
30 define internal i32 @test2(%T* %p, i32 %p2) {
31 %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
32 %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
33 %a = load i32, i32* %a.gep
34 %b = load i32, i32* %b.gep
35 %v = add i32 %a, %b
36 %ca = musttail call i32 @foo(%T* undef, i32 %v)
37 ret i32 %ca
38 }
39
40 ; CHECK-LABEL: define i32 @caller2(%T* %g)
41 define i32 @caller2(%T* %g) {
42 %v = call i32 @test2(%T* %g, i32 0)
43 ret i32 %v
44 }