llvm.org GIT mirror llvm / 44e5d12
Merging r326521: ------------------------------------------------------------------------ r326521 | indutny | 2018-03-01 16:59:27 -0800 (Thu, 01 Mar 2018) | 13 lines [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/branches/release_60@329858 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 5 months ago
2 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
846846 if (CS.getInstruction() == nullptr || !CS.isCallee(&U))
847847 return nullptr;
848848
849 // Can't change signature of musttail callee
850 if (CS.isMustTailCall())
851 return nullptr;
852
849853 if (CS.getInstruction()->getParent()->getParent() == F)
850854 isSelfRecursive = true;
851855 }
856
857 // Can't change signature of musttail caller
858 // FIXME: Support promoting whole chain of musttail functions
859 for (BasicBlock &BB : *F)
860 if (BB.getTerminatingMustTailCall())
861 return nullptr;
852862
853863 const DataLayout &DL = F->getParent()->getDataLayout();
854864
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 }