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
9 define i32 @outer1(i1 %cond) {
10 ; CHECK-LABEL: @outer1(
11 ; CHECK-NOT: call i32 @inner1
12 %C = call i32 @inner1(i1 %cond, i32 1)
16 define i32 @inner1(i1 %cond, i32 %val) {
17 %select = select i1 %cond, i32 1, i32 %val ; Simplified to 1
19 store i32 0, i32* @glbl
20 ret i32 %select ; Simplifies to ret i32 1
24 define i32 @outer2(i32 %val) {
25 ; CHECK-LABEL: @outer2(
26 ; CHECK-NOT: call i32 @inner2
27 %C = call i32 @inner2(i1 true, i32 %val)
31 define i32 @inner2(i1 %cond, i32 %val) {
32 %select = select i1 %cond, i32 1, i32 %val ; Simplifies to 1
34 store i32 0, i32* @glbl
35 ret i32 %select ; Simplifies to ret i32 1
39 define i32 @outer3(i32 %val) {
40 ; CHECK-LABEL: @outer3(
41 ; CHECK-NOT: call i32 @inner3
42 %C = call i32 @inner3(i1 false, i32 %val)
46 define i32 @inner3(i1 %cond, i32 %val) {
47 %select = select i1 %cond, i32 %val, i32 -1 ; Simplifies to -1
49 store i32 0, i32* @glbl
50 ret i32 %select ; Simplifies to ret i32 -1
54 define i32 @outer4() {
55 ; CHECK-LABEL: @outer4(
56 ; CHECK-NOT: call i32 @inner4
57 %C = call i32 @inner4(i1 true, i32 1, i32 -1)
61 define i32 @inner4(i1 %cond, i32 %val1, i32 %val2) {
62 %select = select i1 %cond, i32 %val1, i32 %val2 ; Simplifies to 1
64 store i32 0, i32* @glbl
65 store i32 1, i32* @glbl
66 ret i32 %select ; Simplifies to ret i32 1
71 ; CHECK-LABEL: @outer5(
72 ; CHECK-NOT: call i1 @inner5
73 %C = call i1 @inner5(i1 true, i1 true, i1 false)
79 define i1 @inner5(i1 %cond, i1 %val1, i1 %val2) {
80 %select = select i1 %cond, i1 %val1, i1 %val2 ; Simplifies to true
81 br i1 %select, label %exit, label %isfalse ; Simplifies to br label %end
83 isfalse: ; This block is unreachable once inlined
88 store i32 0, i32* @glbl
89 ret i1 %select ; Simplifies to ret i1 true
93 define i32 @outer6(i1 %cond) {
94 ; CHECK-LABEL: @outer6(
95 ; CHECK-NOT: call i32 @inner6
97 %C = call i32 @inner6(i1 %cond, i32* %A)
101 define i32 @inner6(i1 %cond, i32* %ptr) {
102 %G1 = getelementptr inbounds i32, i32* %ptr, i32 1
103 %G2 = getelementptr inbounds i32, i32* %G1, i32 1
104 %G3 = getelementptr inbounds i32, i32* %ptr, i32 2
105 %select = select i1 %cond, i32* %G2, i32* %G3 ; Simplified to %A[2]
106 %load = load i32, i32* %select ; SROA'ed
108 ret i32 %load ; Simplified
112 define i32 @outer7(i32* %ptr) {
113 ; CHECK-LABEL: @outer7(
114 ; CHECK-NOT: call i32 @inner7
116 %C = call i32 @inner7(i1 true, i32* %A, i32* %ptr)
120 define i32 @inner7(i1 %cond, i32* %p1, i32* %p2) {
121 %select = select i1 %cond, i32* %p1, i32* %p2 ; Simplifies to %A
122 %load = load i32, i32* %select ; SROA'ed
124 store i32 0, i32* @glbl
125 ret i32 %load ; Simplified
129 define i32 @outer8(i32* %ptr) {
130 ; CHECK-LABEL: @outer8(
131 ; CHECK-NOT: call i32 @inner8
133 %C = call i32 @inner8(i1 false, i32* %ptr, i32* %A)
137 define i32 @inner8(i1 %cond, i32* %p1, i32* %p2) {
138 %select = select i1 %cond, i32* %p1, i32* %p2 ; Simplifies to %A
139 %load = load i32, i32* %select ; SROA'ed
141 store i32 0, i32* @glbl
142 ret i32 %load ; Simplified
146 define <2 x i32> @outer9(<2 x i32> %val) {
147 ; CHECK-LABEL: @outer9(
148 ; CHECK-NOT: call <2 x i32> @inner9
149 %C = call <2 x i32> @inner9(<2 x i1> <i1 true, i1 true>, <2 x i32> %val)
153 define <2 x i32> @inner9(<2 x i1> %cond, <2 x i32> %val) {
154 %select = select <2 x i1> %cond, <2 x i32> <i32 1, i32 1>, <2 x i32> %val ; Simplifies to <1, 1>
156 store i32 0, i32* @glbl
157 ret <2 x i32> %select ; Simplifies to ret <2 x i32> <1, 1>
161 define <2 x i32> @outer10(<2 x i32> %val) {
162 ; CHECK-LABEL: @outer10(
163 ; CHECK-NOT: call <2 x i32> @inner10
164 %C = call <2 x i32> @inner10(<2 x i1> <i1 false, i1 false>, <2 x i32> %val)
168 define <2 x i32> @inner10(<2 x i1> %cond, <2 x i32> %val) {
169 %select = select <2 x i1> %cond, < 2 x i32> %val, <2 x i32> <i32 -1, i32 -1> ; Simplifies to <-1, -1>
171 store i32 0, i32* @glbl
172 ret <2 x i32> %select ; Simplifies to ret <2 x i32> <-1, -1>
176 define <2 x i32> @outer11() {
177 ; CHECK-LABEL: @outer11(
178 ; CHECK-NOT: call <2 x i32> @inner11
179 %C = call <2 x i32> @inner11(<2 x i1> <i1 true, i1 false>)
183 define <2 x i32> @inner11(<2 x i1> %cond) {
184 %select = select <2 x i1> %cond, <2 x i32> <i32 1, i32 1>, < 2 x i32> <i32 -1, i32 -1> ; Simplifies to <1, -1>
186 ret <2 x i32> %select ; Simplifies to ret <2 x i32> <1, -1>
190 define i1 @outer12(i32* %ptr) {
191 ; CHECK-LABEL: @outer12(
192 ; CHECK-NOT: call i1 @inner12
193 %C = call i1 @inner12(i1 true, i32* @glbl, i32* %ptr)
197 define i1 @inner12(i1 %cond, i32* %ptr1, i32* %ptr2) {
198 %select = select i1 %cond, i32* %ptr1, i32* %ptr2 ; Simplified to @glbl
199 %cmp = icmp eq i32* %select, @glbl ; Simplified to true
201 store i32 0, i32* @glbl
202 ret i1 %cmp ; Simplifies to ret i1 true
206 define <2 x i32> @outer13(<2 x i32> %val1, <2 x i32> %val2) {
207 ; CHECK-LABEL: @outer13(
208 ; CHECK: call <2 x i32> @inner13
209 %C = call <2 x i32> @inner13(<2 x i1> <i1 true, i1 false>, <2 x i32> %val1, <2 x i32> %val2)
213 define <2 x i32> @inner13(<2 x i1> %cond, <2 x i32> %val1, < 2 x i32> %val2) {
214 %select = select <2 x i1> %cond, <2 x i32> %val1, < 2 x i32> %val2 ; Cannot be Simplified
216 store i32 0, i32* @glbl
217 store i32 1, i32* @glbl
218 ret <2 x i32> %select ; Simplified
222 define i32 @outer14(i32 %val1, i32 %val2) {
223 ; CHECK-LABEL: @outer14(
224 ; CHECK-NOT: call i32 @inner14
225 %C = call i32 @inner14(i1 true, i32 %val1, i32 %val2)
229 define i32 @inner14(i1 %cond, i32 %val1, i32 %val2) {
230 %select = select i1 %cond, i32 %val1, i32 %val2 ; Simplified to %val1
232 store i32 0, i32* @glbl
233 store i32 1, i32* @glbl
234 ret i32 %select ; Simplifies to ret i32 %val1
238 define i32 @outer15(i32 %val1, i32 %val2) {
239 ; CHECK-LABEL: @outer15(
240 ; CHECK-NOT: call i32 @inner15
241 %C = call i32 @inner15(i1 false, i32 %val1, i32 %val2)
245 define i32 @inner15(i1 %cond, i32 %val1, i32 %val2) {
246 %select = select i1 %cond, i32 %val1, i32 %val2 ; Simplified to %val2
248 store i32 0, i32* @glbl
249 store i32 1, i32* @glbl
250 ret i32 %select ; Simplifies to ret i32 %val2