• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -inline -mtriple=aarch64--linux-gnu -S -o - < %s -inline-threshold=0 | FileCheck %s
2
3target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4target triple = "aarch64--linux-gnu"
5
6declare void @pad()
7@glbl = external global i32
8
9define i32 @outer1(i1 %cond) {
10; CHECK-LABEL: @outer1(
11; CHECK-NOT: call i32 @inner1
12  %C = call i32 @inner1(i1 %cond, i32 1)
13  ret i32 %C
14}
15
16define i32 @inner1(i1 %cond, i32 %val) {
17  %select = select i1 %cond, i32 1, i32 %val       ; Simplified to 1
18  call void @pad()
19  store i32 0, i32* @glbl
20  ret i32 %select                                  ; Simplifies to ret i32 1
21}
22
23
24define i32 @outer2(i32 %val) {
25; CHECK-LABEL: @outer2(
26; CHECK-NOT: call i32 @inner2
27  %C = call i32 @inner2(i1 true, i32 %val)
28  ret i32 %C
29}
30
31define i32 @inner2(i1 %cond, i32 %val) {
32  %select = select i1 %cond, i32 1, i32 %val       ; Simplifies to 1
33  call void @pad()
34  store i32 0, i32* @glbl
35  ret i32 %select                                  ; Simplifies to ret i32 1
36}
37
38
39define i32 @outer3(i32 %val) {
40; CHECK-LABEL: @outer3(
41; CHECK-NOT: call i32 @inner3
42  %C = call i32 @inner3(i1 false, i32 %val)
43  ret i32 %C
44}
45
46define i32 @inner3(i1 %cond, i32 %val) {
47  %select = select i1 %cond, i32 %val, i32 -1      ; Simplifies to -1
48  call void @pad()
49  store i32 0, i32* @glbl
50  ret i32 %select                                  ; Simplifies to ret i32 -1
51}
52
53
54define i32 @outer4() {
55; CHECK-LABEL: @outer4(
56; CHECK-NOT: call i32 @inner4
57  %C = call i32 @inner4(i1 true, i32 1, i32 -1)
58  ret i32 %C
59}
60
61define i32 @inner4(i1 %cond, i32 %val1, i32 %val2) {
62  %select = select i1 %cond, i32 %val1, i32 %val2  ; Simplifies to 1
63  call void @pad()
64  store i32 0, i32* @glbl
65  store i32 1, i32* @glbl
66  ret i32 %select                                  ; Simplifies to ret i32 1
67}
68
69
70define i1 @outer5() {
71; CHECK-LABEL: @outer5(
72; CHECK-NOT: call i1 @inner5
73  %C = call i1 @inner5(i1 true, i1 true, i1 false)
74  ret i1 %C
75}
76
77declare void @dead()
78
79define 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
82
83isfalse:                                           ; This block is unreachable once inlined
84  call void @dead()
85  br label %exit
86
87exit:
88  store i32 0, i32* @glbl
89  ret i1 %select                                   ; Simplifies to ret i1 true
90}
91
92
93define i32 @outer6(i1 %cond) {
94; CHECK-LABEL: @outer6(
95; CHECK-NOT: call i32 @inner6
96  %A = alloca i32
97  %C = call i32 @inner6(i1 %cond, i32* %A)
98  ret i32 %C
99}
100
101define 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
107  call void @pad()
108  ret i32 %load                                    ; Simplified
109}
110
111
112define i32 @outer7(i32* %ptr) {
113; CHECK-LABEL: @outer7(
114; CHECK-NOT: call i32 @inner7
115  %A = alloca i32
116  %C = call i32 @inner7(i1 true, i32* %A, i32* %ptr)
117  ret i32 %C
118}
119
120define 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
123  call void @pad()
124  store i32 0, i32* @glbl
125  ret i32 %load                                    ; Simplified
126}
127
128
129define i32 @outer8(i32* %ptr) {
130; CHECK-LABEL: @outer8(
131; CHECK-NOT: call i32 @inner8
132  %A = alloca i32
133  %C = call i32 @inner8(i1 false, i32* %ptr, i32* %A)
134  ret i32 %C
135}
136
137define 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
140  call void @pad()
141  store i32 0, i32* @glbl
142  ret i32 %load                                    ; Simplified
143}
144
145
146define <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)
150  ret <2 x i32> %C
151}
152
153define <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>
155  call void @pad()
156  store i32 0, i32* @glbl
157  ret <2 x i32> %select                                                                  ; Simplifies to ret <2 x i32> <1, 1>
158}
159
160
161define <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)
165  ret <2 x i32> %C
166}
167
168define <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>
170  call void @pad()
171  store i32 0, i32* @glbl
172  ret <2 x i32> %select                                                                  ; Simplifies to ret <2 x i32> <-1, -1>
173}
174
175
176define <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>)
180  ret <2 x i32> %C
181}
182
183define <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>
185  call void @pad()
186  ret <2 x i32> %select                                                                  ; Simplifies to ret <2 x i32> <1, -1>
187}
188
189
190define 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)
194  ret i1 %C
195}
196
197define 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
200  call void @pad()
201  store i32 0, i32* @glbl
202  ret i1 %cmp                                       ; Simplifies to ret i1 true
203}
204
205
206define <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)
210  ret <2 x i32> %C
211}
212
213define <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
215  call void @pad()
216  store i32 0, i32* @glbl
217  store i32 1, i32* @glbl
218  ret <2 x i32> %select                                              ; Simplified
219}
220
221
222define 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)
226  ret i32 %C
227}
228
229define i32 @inner14(i1 %cond, i32 %val1, i32 %val2) {
230  %select = select i1 %cond, i32 %val1, i32 %val2   ; Simplified to %val1
231  call void @pad()
232  store i32 0, i32* @glbl
233  store i32 1, i32* @glbl
234  ret i32 %select                                   ; Simplifies to ret i32 %val1
235}
236
237
238define 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)
242  ret i32 %C
243}
244
245define i32 @inner15(i1 %cond, i32 %val1, i32 %val2) {
246  %select = select i1 %cond, i32 %val1, i32 %val2   ; Simplified to %val2
247  call void @pad()
248  store i32 0, i32* @glbl
249  store i32 1, i32* @glbl
250  ret i32 %select                                   ; Simplifies to ret i32 %val2
251}
252