1 ; RUN: opt < %s -inline -inline-threshold=20 -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -inline-threshold=20 -S | FileCheck %s
4 define internal i32 @callee1(i32 %A, i32 %B) {
9 define i32 @caller1() {
10 ; CHECK-LABEL: define i32 @caller1(
11 ; CHECK-NEXT: ret i32 3
13 %X = call i32 @callee1( i32 10, i32 3 )
17 define i32 @caller2() {
18 ; Check that we can constant-prop through instructions after inlining callee21
19 ; to get constants in the inlined callsite to callee22.
20 ; FIXME: Currently, the threshold is fixed at 20 because we don't perform
21 ; *recursive* cost analysis to realize that the nested call site will definitely
22 ; inline and be cheap. We should eventually do that and lower the threshold here
25 ; CHECK-LABEL: @caller2(
26 ; CHECK-NOT: call void @callee2
29 %x = call i32 @callee21(i32 42, i32 48)
33 define i32 @callee21(i32 %x, i32 %y) {
35 %result = call i32 @callee22(i32 %sub)
41 define i32 @callee22(i32 %x) {
42 %icmp = icmp ugt i32 %x, 42
43 br i1 %icmp, label %bb.true, label %bb.false
45 ; This block musn't be counted in the inline cost.
60 define i32 @caller3() {
61 ; Check that even if the expensive path is hidden behind several basic blocks,
62 ; it doesn't count toward the inline cost when constant-prop proves those paths
65 ; CHECK-LABEL: @caller3(
70 %x = call i32 @callee3(i32 42, i32 48)
74 define i32 @callee3(i32 %x, i32 %y) {
76 %icmp = icmp ugt i32 %sub, 42
77 br i1 %icmp, label %bb.true, label %bb.false
80 %icmp2 = icmp ult i32 %sub, 64
81 br i1 %icmp2, label %bb.true.true, label %bb.true.false
84 ; This block musn't be counted in the inline cost.
96 ; This block musn't be counted in the inline cost.
108 %result = phi i32 [ %x8, %bb.true.true ], [ %y8, %bb.true.false ]
115 declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b)
117 define i8 @caller4(i8 %z) {
118 ; Check that we can constant fold through intrinsics such as the
119 ; overflow-detecting arithmetic instrinsics. These are particularly important
120 ; as they are used heavily in standard library code and generic C++ code where
121 ; the arguments are oftent constant but complete generality is required.
123 ; CHECK-LABEL: @caller4(
128 %x = call i8 @callee4(i8 254, i8 14, i8 %z)
132 define i8 @callee4(i8 %x, i8 %y, i8 %z) {
133 %uadd = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %x, i8 %y)
134 %o = extractvalue {i8, i1} %uadd, 1
135 br i1 %o, label %bb.true, label %bb.false
141 ; This block musn't be counted in the inline cost.
153 define i64 @caller5(i64 %y) {
154 ; Check that we can round trip constants through various kinds of casts etc w/o
155 ; losing track of the constant prop in the inline cost analysis.
157 ; CHECK-LABEL: @caller5(
162 %x = call i64 @callee5(i64 42, i64 %y)
166 define i64 @callee5(i64 %x, i64 %y) {
167 %inttoptr = inttoptr i64 %x to i8*
168 %bitcast = bitcast i8* %inttoptr to i32*
169 %ptrtoint = ptrtoint i32* %bitcast to i64
170 %trunc = trunc i64 %ptrtoint to i32
171 %zext = zext i32 %trunc to i64
172 %cmp = icmp eq i64 %zext, 42
173 br i1 %cmp, label %bb.true, label %bb.false
179 ; This block musn't be counted in the inline cost.
191 define float @caller6() {
192 ; Check that we can constant-prop through fcmp instructions
194 ; CHECK-LABEL: @caller6(
197 %x = call float @callee6(float 42.0)
201 define float @callee6(float %x) {
202 %icmp = fcmp ugt float %x, 42.0
203 br i1 %icmp, label %bb.true, label %bb.false
206 ; This block musn't be counted in the inline cost.
207 %x1 = fadd float %x, 1.0
208 %x2 = fadd float %x1, 1.0
209 %x3 = fadd float %x2, 1.0
210 %x4 = fadd float %x3, 1.0
211 %x5 = fadd float %x4, 1.0
212 %x6 = fadd float %x5, 1.0
213 %x7 = fadd float %x6, 1.0
214 %x8 = fadd float %x7, 1.0
223 define i32 @PR13412.main() {
224 ; This is a somewhat complicated three layer subprogram that was reported to
225 ; compute the wrong value for a branch due to assuming that an argument
226 ; mid-inline couldn't be equal to another pointer.
228 ; After inlining, the branch should point directly to the exit block, not to
229 ; the intermediate block.
230 ; CHECK: @PR13412.main
231 ; CHECK: br i1 true, label %[[TRUE_DEST:.*]], label %[[FALSE_DEST:.*]]
232 ; CHECK: [[FALSE_DEST]]:
233 ; CHECK-NEXT: call void @PR13412.fail()
234 ; CHECK: [[TRUE_DEST]]:
235 ; CHECK-NEXT: ret i32 0
239 store i64 0, i64* %i1
240 %arraydecay = bitcast i64* %i1 to i32*
241 %call = call i1 @PR13412.first(i32* %arraydecay, i32* %arraydecay)
242 br i1 %call, label %cond.end, label %cond.false
245 call void @PR13412.fail()
252 define internal i1 @PR13412.first(i32* %a, i32* %b) {
254 %call = call i32* @PR13412.second(i32* %a, i32* %b)
255 %cmp = icmp eq i32* %call, %b
259 declare void @PR13412.fail()
261 define internal i32* @PR13412.second(i32* %a, i32* %b) {
263 %sub.ptr.lhs.cast = ptrtoint i32* %b to i64
264 %sub.ptr.rhs.cast = ptrtoint i32* %a to i64
265 %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
266 %sub.ptr.div = ashr exact i64 %sub.ptr.sub, 2
267 %cmp = icmp ugt i64 %sub.ptr.div, 1
268 br i1 %cmp, label %if.then, label %if.end3
271 %0 = load i32, i32* %a
272 %1 = load i32, i32* %b
273 %cmp1 = icmp eq i32 %0, %1
274 br i1 %cmp1, label %return, label %if.end3
280 %retval.0 = phi i32* [ %b, %if.end3 ], [ %a, %if.then ]
284 declare i32 @PR28802.external(i32 returned %p1)
286 define internal i32 @PR28802.callee() {
291 %0 = phi i32 [ 0, %entry ]
292 %call = call i32 @PR28802.external(i32 %0)
296 define i32 @PR28802() {
298 %call = call i32 @PR28802.callee()
302 ; CHECK-LABEL: define i32 @PR28802(
303 ; CHECK: %[[call:.*]] = call i32 @PR28802.external(i32 0)
304 ; CHECK: ret i32 %[[call]]
306 define internal i32 @PR28848.callee(i32 %p2, i1 %c) {
308 br i1 %c, label %cond.end, label %cond.true
314 %cond = phi i32 [ 0, %cond.true ], [ %p2, %entry ]
315 %or = or i32 %cond, %p2
319 define i32 @PR28848() {
321 %call = call i32 @PR28848.callee(i32 0, i1 false)
324 ; CHECK-LABEL: define i32 @PR28848(
327 define internal void @callee7(i16 %param1, i16 %param2) {
332 %phi = phi i16 [ %param2, %entry ]
333 %add = add i16 %phi, %param1
337 declare i16 @caller7.external(i16 returned)
339 define void @caller7() {
341 %call = call i16 @caller7.external(i16 1)
342 call void @callee7(i16 0, i16 %call)
345 ; CHECK-LABEL: define void @caller7(
346 ; CHECK: %call = call i16 @caller7.external(i16 1)
347 ; CHECK-NEXT: ret void
349 define float @caller8(float %y) {
350 ; Check that we can constant-prop through fneg instructions
352 ; CHECK-LABEL: @caller8(
355 %x = call float @callee8(float -42.0, float %y)
359 define float @callee8(float %x, float %y) {
361 %icmp = fcmp ugt float %neg, 42.0
362 br i1 %icmp, label %bb.true, label %bb.false
365 ; This block musn't be counted in the inline cost.
366 %y1 = fadd float %y, 1.0
367 %y2 = fadd float %y1, 1.0
368 %y3 = fadd float %y2, 1.0
369 %y4 = fadd float %y3, 1.0
370 %y5 = fadd float %y4, 1.0
371 %y6 = fadd float %y5, 1.0
372 %y7 = fadd float %y6, 1.0
373 %y8 = fadd float %y7, 1.0