1 ; RUN: opt -inline -mtriple=aarch64--linux-gnu -S -o - < %s -inline-threshold=0 | FileCheck %s
3 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4 target triple = "aarch64--linux-gnu"
7 @glbl = external global i32
10 ; CHECK-LABEL: @outer1(
11 ; CHECK-NOT: call i1 @inner1
12 %C = call i1 @inner1()
21 %phi = phi i1 [0, %entry], [%phi, %if_true] ; Simplified to 0
22 br i1 %phi, label %if_true, label %exit
25 store i32 0, i32* @glbl
26 store i32 1, i32* @glbl
27 store i32 2, i32* @glbl
28 store i32 3, i32* @glbl
29 store i32 4, i32* @glbl
34 define i1 @outer2(i1 %val) {
35 ; CHECK-LABEL: @outer2(
36 ; CHECK: call i1 @inner2
37 %C = call i1 @inner2(i1 %val)
41 define i1 @inner2(i1 %val) {
46 %phi = phi i1 [%val, %entry], [%phi, %if_true] ; Cannot be simplified to a constant
47 br i1 %phi, label %if_true, label %exit
55 define i1 @outer3(i1 %cond) {
56 ; CHECK-LABEL: @outer3(
57 ; CHECK-NOT: call i1 @inner3
58 %C = call i1 @inner3(i1 %cond)
62 define i1 @inner3(i1 %cond) {
64 br i1 %cond, label %if_true, label %exit
70 %phi = phi i32 [0, %entry], [0, %if_true] ; Simplified to 0
71 %cmp = icmp eq i32 %phi, 0
72 store i32 0, i32* @glbl
73 store i32 1, i32* @glbl
74 store i32 2, i32* @glbl
75 store i32 3, i32* @glbl
76 store i32 4, i32* @glbl
81 define i1 @outer4(i1 %cond) {
82 ; CHECK-LABEL: @outer4(
83 ; CHECK-NOT: call i1 @inner4
84 %C = call i1 @inner4(i1 %cond, i32 0)
88 define i1 @inner4(i1 %cond, i32 %val) {
90 br i1 %cond, label %if_true, label %exit
96 %phi = phi i32 [0, %entry], [%val, %if_true] ; Simplified to 0
97 %cmp = icmp eq i32 %phi, 0
103 define i1 @outer5_1(i1 %cond) {
104 ; CHECK-LABEL: @outer5_1(
105 ; CHECK-NOT: call i1 @inner5
106 %C = call i1 @inner5(i1 %cond, i32 0, i32 0)
111 define i1 @outer5_2(i1 %cond) {
112 ; CHECK-LABEL: @outer5_2(
113 ; CHECK: call i1 @inner5
114 %C = call i1 @inner5(i1 %cond, i32 0, i32 1)
118 define i1 @inner5(i1 %cond, i32 %val1, i32 %val2) {
120 br i1 %cond, label %if_true, label %exit
126 %phi = phi i32 [%val1, %entry], [%val2, %if_true] ; Can be simplified to a constant if %val1 and %val2 are the same constants
127 %cmp = icmp eq i32 %phi, 0
129 store i32 0, i32* @glbl
134 define i1 @outer6(i1 %cond, i32 %val) {
135 ; CHECK-LABEL: @outer6(
136 ; CHECK-NOT: call i1 @inner6
137 %C = call i1 @inner6(i1 true, i32 %val, i32 0)
141 define i1 @inner6(i1 %cond, i32 %val1, i32 %val2) {
143 br i1 %cond, label %if_true, label %exit
149 %phi = phi i32 [%val1, %entry], [%val2, %if_true] ; Simplified to 0
150 %cmp = icmp eq i32 %phi, 0
152 store i32 0, i32* @glbl
153 store i32 1, i32* @glbl
158 define i1 @outer7(i1 %cond, i32 %val) {
159 ; CHECK-LABEL: @outer7(
160 ; CHECK-NOT: call i1 @inner7
161 %C = call i1 @inner7(i1 false, i32 0, i32 %val)
165 define i1 @inner7(i1 %cond, i32 %val1, i32 %val2) {
167 br i1 %cond, label %if_true, label %exit
173 %phi = phi i32 [%val1, %entry], [%val2, %if_true] ; Simplified to 0
174 %cmp = icmp eq i32 %phi, 0
176 store i32 0, i32* @glbl
177 store i32 1, i32* @glbl
182 define i1 @outer8_1() {
183 ; CHECK-LABEL: @outer8_1(
184 ; CHECK-NOT: call i1 @inner8
185 %C = call i1 @inner8(i32 0)
191 define i1 @outer8_2() {
192 ; CHECK-LABEL: @outer8_2(
193 ; CHECK-NOT: call i1 @inner8
194 %C = call i1 @inner8(i32 3)
198 define i1 @inner8(i32 %cond) {
200 switch i32 %cond, label %default [ i32 0, label %zero
217 %phi = phi i32 [0, %zero], [1, %one], [2, %two], [-1, %default] ; Can be simplified to a constant if the switch condition is known
218 %cmp = icmp eq i32 %phi, 0
224 define i1 @outer9(i1 %cond) {
225 ; CHECK-LABEL: @outer9(
226 ; CHECK-NOT: call i1 @inner9
227 %C = call i1 @inner9(i32 0, i1 %cond)
231 define i1 @inner9(i32 %cond1, i1 %cond2) {
233 switch i32 %cond1, label %exit [ i32 0, label %zero
244 br i1 %cond2, label %two_true, label %two_false
253 %phi = phi i32 [0, %zero], [1, %one], [2, %two_true], [2, %two_false], [-1, %entry] ; Simplified to 0
254 %cmp = icmp eq i32 %phi, 0
256 store i32 0, i32* @glbl
261 define i32 @outer10(i1 %cond) {
262 ; CHECK-LABEL: @outer10(
263 ; CHECK-NOT: call i32 @inner10
265 %C = call i32 @inner10(i1 %cond, i32* %A)
269 define i32 @inner10(i1 %cond, i32* %A) {
274 %phi = phi i32* [%A, %entry], [%phi, %if_true] ; Simplified to %A
275 %load = load i32, i32* %phi
276 br i1 %cond, label %if_true, label %exit
284 define i32 @outer11(i1 %cond, i32* %ptr) {
285 ; CHECK-LABEL: @outer11(
286 ; CHECK: call i32 @inner11
287 %C = call i32 @inner11(i1 %cond, i32* %ptr)
291 define i32 @inner11(i1 %cond, i32* %ptr) {
296 %phi = phi i32* [%ptr, %entry], [%phi, %if_true] ; Cannot be simplified
297 %load = load i32, i32* %phi
298 br i1 %cond, label %if_true, label %exit
306 define i32 @outer12(i1 %cond) {
307 ; CHECK-LABEL: @outer12(
308 ; CHECK-NOT: call i32 @inner12
310 %C = call i32 @inner12(i1 %cond, i32* %A)
314 define i32 @inner12(i1 %cond, i32* %ptr) {
316 br i1 %cond, label %if_true, label %exit
322 %phi = phi i32* [%ptr, %entry], [%ptr, %if_true] ; Simplified to %A
323 %load = load i32, i32* %phi
329 define i32 @outer13(i1 %cond) {
330 ; CHECK-LABEL: @outer13(
331 ; CHECK-NOT: call i32 @inner13
333 %C = call i32 @inner13(i1 %cond, i32* %A)
337 define i32 @inner13(i1 %cond, i32* %ptr) {
339 %gep1 = getelementptr inbounds i32, i32* %ptr, i32 2
340 %gep2 = getelementptr inbounds i32, i32* %ptr, i32 1
341 br i1 %cond, label %if_true, label %exit
344 %gep3 = getelementptr inbounds i32, i32* %gep2, i32 1
348 %phi = phi i32* [%gep1, %entry], [%gep3, %if_true] ; Simplifeid to %gep1
349 %load = load i32, i32* %phi
355 define i32 @outer14(i1 %cond) {
356 ; CHECK-LABEL: @outer14(
357 ; CHECK: call i32 @inner14
360 %C = call i32 @inner14(i1 %cond, i32* %A1, i32* %A2)
364 define i32 @inner14(i1 %cond, i32* %ptr1, i32* %ptr2) {
366 br i1 %cond, label %if_true, label %exit
372 %phi = phi i32* [%ptr1, %entry], [%ptr2, %if_true] ; Cannot be simplified
373 %load = load i32, i32* %phi
375 store i32 0, i32* @glbl
380 define i32 @outer15(i1 %cond, i32* %ptr) {
381 ; CHECK-LABEL: @outer15(
382 ; CHECK-NOT: call i32 @inner15
384 %C = call i32 @inner15(i1 true, i32* %ptr, i32* %A)
388 define i32 @inner15(i1 %cond, i32* %ptr1, i32* %ptr2) {
390 br i1 %cond, label %if_true, label %exit
396 %phi = phi i32* [%ptr1, %entry], [%ptr2, %if_true] ; Simplified to %A
397 %load = load i32, i32* %phi
399 store i32 0, i32* @glbl
400 store i32 1, i32* @glbl
405 define i32 @outer16(i1 %cond, i32* %ptr) {
406 ; CHECK-LABEL: @outer16(
407 ; CHECK-NOT: call i32 @inner16
409 %C = call i32 @inner16(i1 false, i32* %A, i32* %ptr)
413 define i32 @inner16(i1 %cond, i32* %ptr1, i32* %ptr2) {
415 br i1 %cond, label %if_true, label %exit
421 %phi = phi i32* [%ptr1, %entry], [%ptr2, %if_true] ; Simplified to %A
422 %load = load i32, i32* %phi
424 store i32 0, i32* @glbl
425 store i32 1, i32* @glbl
430 define i1 @outer17(i1 %cond) {
431 ; CHECK-LABEL: @outer17(
432 ; CHECK: call i1 @inner17
434 %C = call i1 @inner17(i1 %cond, i32* %A)
438 define i1 @inner17(i1 %cond, i32* %ptr) {
440 br i1 %cond, label %if_true, label %exit
446 %phi = phi i32* [null, %entry], [%ptr, %if_true] ; Cannot be mapped to a constant
447 %cmp = icmp eq i32* %phi, null
453 define i1 @outer18(i1 %cond) {
454 ; CHECK-LABEL: @outer18(
455 ; CHECK-NOT: call i1 @inner18
456 %C = call i1 @inner18(i1 %cond, i1 true)
460 define i1 @inner18(i1 %cond1, i1 %cond2) {
462 br i1 %cond1, label %block1, label %block2
465 br i1 %cond2, label %block3, label %block4
468 br i1 %cond2, label %block5, label %block4
471 %phi = phi i32 [0, %block1], [1, %block4], [0, %block5] ; Simplified to 0
472 %cmp = icmp eq i32 %phi, 0
476 block4: ; Unreachable block
484 define i1 @outer19(i1 %cond) {
485 ; CHECK-LABEL: @outer19(
486 ; CHECK: call i1 @inner19
488 %C = call i1 @inner19(i1 %cond, i32* %A)
492 define i1 @inner19(i1 %cond, i32* %ptr) {
494 br i1 %cond, label %if_true, label %exit
500 %phi = phi i32* [%ptr, %entry], [null, %if_true] ; Cannot be mapped to a constant
501 %cmp = icmp eq i32* %phi, null