1 ; RUN: opt < %s -inline -inline-threshold=20 -S | FileCheck %s
3 define internal i32 @callee1(i32 %A, i32 %B) {
8 define i32 @caller1() {
9 ; CHECK: define i32 @caller1
10 ; CHECK-NEXT: ret i32 3
12 %X = call i32 @callee1( i32 10, i32 3 )
16 define i32 @caller2() {
17 ; Check that we can constant-prop through instructions after inlining callee21
18 ; to get constants in the inlined callsite to callee22.
19 ; FIXME: Currently, the threshold is fixed at 20 because we don't perform
20 ; *recursive* cost analysis to realize that the nested call site will definitely
21 ; inline and be cheap. We should eventually do that and lower the threshold here
25 ; CHECK-NOT: call void @callee2
28 %x = call i32 @callee21(i32 42, i32 48)
32 define i32 @callee21(i32 %x, i32 %y) {
34 %result = call i32 @callee22(i32 %sub)
40 define i32 @callee22(i32 %x) {
41 %icmp = icmp ugt i32 %x, 42
42 br i1 %icmp, label %bb.true, label %bb.false
44 ; This block musn't be counted in the inline cost.
59 define i32 @caller3() {
60 ; Check that even if the expensive path is hidden behind several basic blocks,
61 ; it doesn't count toward the inline cost when constant-prop proves those paths
69 %x = call i32 @callee3(i32 42, i32 48)
73 define i32 @callee3(i32 %x, i32 %y) {
75 %icmp = icmp ugt i32 %sub, 42
76 br i1 %icmp, label %bb.true, label %bb.false
79 %icmp2 = icmp ult i32 %sub, 64
80 br i1 %icmp2, label %bb.true.true, label %bb.true.false
83 ; This block musn't be counted in the inline cost.
95 ; This block musn't be counted in the inline cost.
107 %result = phi i32 [ %x8, %bb.true.true ], [ %y8, %bb.true.false ]
115 define i32 @PR13412.main() {
116 ; This is a somewhat complicated three layer subprogram that was reported to
117 ; compute the wrong value for a branch due to assuming that an argument
118 ; mid-inline couldn't be equal to another pointer.
120 ; After inlining, the branch should point directly to the exit block, not to
121 ; the intermediate block.
122 ; CHECK: @PR13412.main
123 ; CHECK: br i1 true, label %[[TRUE_DEST:.*]], label %[[FALSE_DEST:.*]]
124 ; CHECK: [[FALSE_DEST]]:
125 ; CHECK-NEXT: call void @PR13412.fail()
126 ; CHECK: [[TRUE_DEST]]:
127 ; CHECK-NEXT: ret i32 0
131 store i64 0, i64* %i1
132 %arraydecay = bitcast i64* %i1 to i32*
133 %call = call i1 @PR13412.first(i32* %arraydecay, i32* %arraydecay)
134 br i1 %call, label %cond.end, label %cond.false
137 call void @PR13412.fail()
144 define internal i1 @PR13412.first(i32* %a, i32* %b) {
146 %call = call i32* @PR13412.second(i32* %a, i32* %b)
147 %cmp = icmp eq i32* %call, %b
151 declare void @PR13412.fail()
153 define internal i32* @PR13412.second(i32* %a, i32* %b) {
155 %sub.ptr.lhs.cast = ptrtoint i32* %b to i64
156 %sub.ptr.rhs.cast = ptrtoint i32* %a to i64
157 %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
158 %sub.ptr.div = ashr exact i64 %sub.ptr.sub, 2
159 %cmp = icmp ugt i64 %sub.ptr.div, 1
160 br i1 %cmp, label %if.then, label %if.end3
165 %cmp1 = icmp eq i32 %0, %1
166 br i1 %cmp1, label %return, label %if.end3
172 %retval.0 = phi i32* [ %b, %if.end3 ], [ %a, %if.then ]