]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Transforms/InstCombine/select_meta.ll
Vendor import of llvm trunk r338150:
[FreeBSD/FreeBSD.git] / test / Transforms / InstCombine / select_meta.ll
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; and enhanced to include metadata checking.
3
4 ; RUN: opt < %s -instcombine -S | FileCheck %s
5
6 define i32 @foo(i32) local_unnamed_addr #0  {
7 ; CHECK-LABEL: @foo(
8 ; CHECK-NEXT:    [[TMP2:%.*]] = icmp sgt i32 %0, 2
9 ; CHECK-NEXT:    [[DOTV:%.*]] = select i1 [[TMP2]], i32 20, i32 -20, !prof ![[$MD1:[0-9]+]]
10 ; CHECK-NEXT:    [[TMP3:%.*]] = add i32 [[DOTV]], %0
11 ; CHECK-NEXT:    ret i32 [[TMP3]]
12 ;
13   %2 = icmp sgt i32 %0, 2
14   %3 = add nsw i32 %0, 20
15   %4 = add nsw i32 %0, -20
16   select i1 %2, i32 %3, i32 %4, !prof !1
17   ret i32 %5
18 }
19
20 define i8 @shrink_select(i1 %cond, i32 %x) {
21 ; CHECK-LABEL: @shrink_select(
22 ; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 %x to i8
23 ; CHECK-NEXT:    [[TRUNC:%.*]] = select i1 %cond, i8 [[TMP1]], i8 42, !prof ![[$MD1]]
24 ; CHECK-NEXT:    ret i8 [[TRUNC]]
25 ;
26   %sel = select i1 %cond, i32 %x, i32 42, !prof !1
27   %trunc = trunc i32 %sel to i8
28   ret i8 %trunc
29 }
30
31 define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) {
32 ; CHECK-LABEL: @min_max_bitcast(
33 ; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt <4 x float> %a, %b
34 ; CHECK-NEXT:    [[SEL1_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> %a, <4 x float> %b, !prof ![[$MD1]]
35 ; CHECK-NEXT:    [[SEL2_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> %b, <4 x float> %a, !prof ![[$MD1]]
36 ; CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i32>* %ptr1 to <4 x float>*
37 ; CHECK-NEXT:    store <4 x float> [[SEL1_V]], <4 x float>* [[TMP1]], align 16
38 ; CHECK-NEXT:    [[TMP2:%.*]] = bitcast <4 x i32>* %ptr2 to <4 x float>*
39 ; CHECK-NEXT:    store <4 x float> [[SEL2_V]], <4 x float>* [[TMP2]], align 16
40 ; CHECK-NEXT:    ret void
41 ;
42   %cmp = fcmp olt <4 x float> %a, %b
43   %bc1 = bitcast <4 x float> %a to <4 x i32>
44   %bc2 = bitcast <4 x float> %b to <4 x i32>
45   %sel1 = select <4 x i1> %cmp, <4 x i32> %bc1, <4 x i32> %bc2, !prof !1
46   %sel2 = select <4 x i1> %cmp, <4 x i32> %bc2, <4 x i32> %bc1, !prof !1
47   store <4 x i32> %sel1, <4 x i32>* %ptr1
48   store <4 x i32> %sel2, <4 x i32>* %ptr2
49   ret void
50 }
51
52 define i32 @foo2(i32, i32) local_unnamed_addr #0  {
53 ; CHECK-LABEL: @foo2(
54 ; CHECK-NEXT:    [[TMP3:%.*]] = icmp sgt i32 %0, 2
55 ; CHECK-NEXT:    [[TMP4:%.*]] = sub i32 0, %1
56 ; CHECK-NEXT:    [[DOTP:%.*]] = select i1 [[TMP3]], i32 %1, i32 [[TMP4]], !prof ![[$MD1]]
57 ; CHECK-NEXT:    [[TMP5:%.*]] = add i32 [[DOTP]], %0
58 ; CHECK-NEXT:    ret i32 [[TMP5]]
59 ;
60   %3 = icmp sgt i32 %0, 2
61   %4 = add nsw i32 %0, %1
62   %5 = sub nsw i32 %0, %1
63   select i1 %3, i32 %4, i32 %5, !prof !1
64   ret i32 %6
65 }
66
67 define i64 @test43(i32 %a) nounwind {
68 ; CHECK-LABEL: @test43(
69 ; CHECK-NEXT:    [[A_EXT:%.*]] = sext i32 %a to i64
70 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i64 [[A_EXT]], 0
71 ; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[TMP1]], i64 [[A_EXT]], i64 0, !prof ![[$MD1]]
72 ; CHECK-NEXT:    ret i64 [[MAX]]
73 ;
74   %a_ext = sext i32 %a to i64
75   %is_a_nonnegative = icmp sgt i32 %a, -1
76   %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0, !prof !1
77   ret i64 %max
78 }
79
80 define <2 x i32> @scalar_select_of_vectors_sext(<2 x i1> %cca, i1 %ccb) {
81 ; CHECK-LABEL: @scalar_select_of_vectors_sext(
82 ; CHECK-NEXT:    [[NARROW:%.*]] = select i1 %ccb, <2 x i1> %cca, <2 x i1> zeroinitializer, !prof ![[$MD1]]
83 ; CHECK-NEXT:    [[R:%.*]] = sext <2 x i1> [[NARROW]] to <2 x i32>
84 ; CHECK-NEXT:    ret <2 x i32> [[R]]
85 ;
86   %ccax = sext <2 x i1> %cca to <2 x i32>
87   %r = select i1 %ccb, <2 x i32> %ccax, <2 x i32> <i32 0, i32 0>, !prof !1
88   ret <2 x i32> %r
89 }
90
91
92 define i16 @t7(i32 %a) {
93 ; CHECK-LABEL: @t7(
94 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp slt i32 %a, -32768
95 ; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], i32 %a, i32 -32768, !prof ![[$MD1]]
96 ; CHECK-NEXT:    [[TMP3:%.*]] = trunc i32 [[TMP2]] to i16
97 ; CHECK-NEXT:    ret i16 [[TMP3]]
98 ;
99   %1 = icmp slt i32 %a, -32768
100   %2 = trunc i32 %a to i16
101   %3 = select i1 %1, i16 %2, i16 -32768, !prof !1
102   ret i16 %3
103 }
104
105 define i32 @abs_nabs_x01(i32 %x) {
106 ; CHECK-LABEL: @abs_nabs_x01(
107 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 %x, 0
108 ; CHECK-NEXT:    [[SUB:%.*]] = sub nsw i32 0, %x
109 ; CHECK-NEXT:    [[COND1:%.*]] = select i1 [[CMP]], i32 [[SUB]], i32 %x, !prof ![[$MD3:[0-9]+]]
110 ; CHECK-NEXT:    ret i32 [[COND1]]
111 ;
112   %cmp = icmp sgt i32 %x, -1
113   %sub = sub nsw i32 0, %x
114   %cond = select i1 %cmp, i32 %sub, i32 %x, !prof !1
115   %cmp1 = icmp sgt i32 %cond, -1
116   %sub16 = sub nsw i32 0, %cond
117   %cond18 = select i1 %cmp1, i32 %cond, i32 %sub16, !prof !2
118   ret i32 %cond18
119 }
120
121 ; Swap predicate / metadata order
122
123 define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) {
124 ; CHECK-LABEL: @abs_nabs_x01_vec(
125 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt <2 x i32> %x, zeroinitializer
126 ; CHECK-NEXT:    [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x
127 ; CHECK-NEXT:    [[COND1:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> %x, !prof ![[$MD3]]
128 ; CHECK-NEXT:    ret <2 x i32> [[COND1]]
129 ;
130   %cmp = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
131   %sub = sub nsw <2 x i32> zeroinitializer, %x
132   %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x, !prof !1
133   %cmp1 = icmp sgt <2 x i32> %cond, <i32 -1, i32 -1>
134   %sub16 = sub nsw <2 x i32> zeroinitializer, %cond
135   %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16, !prof !2
136   ret <2 x i32> %cond18
137 }
138
139 ; SMAX(SMAX(x, y), x) -> SMAX(x, y)
140 define i32 @test30(i32 %x, i32 %y) {
141 ; CHECK-LABEL: @test30(
142 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 %x, %y
143 ; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], i32 %x, i32 %y, !prof ![[$MD1]]
144 ; CHECK-NEXT:    ret i32 [[COND]]
145 ;
146   %cmp = icmp sgt i32 %x, %y
147   %cond = select i1 %cmp, i32 %x, i32 %y, !prof !1
148   %cmp5 = icmp sgt i32 %cond, %x
149   %retval = select i1 %cmp5, i32 %cond, i32 %x, !prof !2
150   ret i32 %retval
151 }
152
153 ; SMAX(SMAX(75, X), 36) -> SMAX(X, 75)
154 define i32 @test70(i32 %x) {
155 ; CHECK-LABEL: @test70(
156 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i32 %x, 75
157 ; CHECK-NEXT:    [[COND:%.*]] = select i1 [[TMP1]], i32 %x, i32 75, !prof ![[$MD3]]
158 ; CHECK-NEXT:    ret i32 [[COND]]
159 ;
160   %cmp = icmp slt i32 %x, 75
161   %cond = select i1 %cmp, i32 75, i32 %x, !prof !1
162   %cmp3 = icmp slt i32 %cond, 36
163   %retval = select i1 %cmp3, i32 36, i32 %cond, !prof !2
164   ret i32 %retval
165 }
166
167 ; Swap predicate / metadata order
168 ; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11)
169 define i32 @test72(i32 %x) {
170 ; CHECK-LABEL: @test72(
171 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp slt i32 %x, 11
172 ; CHECK-NEXT:    [[RETVAL:%.*]] = select i1 [[TMP1]], i32 %x, i32 11, !prof ![[$MD4:[0-9]+]]
173 ; CHECK-NEXT:    ret i32 [[RETVAL]]
174 ;
175   %cmp = icmp sgt i32 %x, 92
176   %cond = select i1 %cmp, i32 92, i32 %x, !prof !1
177   %cmp3 = icmp sgt i32 %cond, 11
178   %retval = select i1 %cmp3, i32 11, i32 %cond, !prof !2
179   ret i32 %retval
180 }
181
182 ; Swap predicate / metadata order
183 ; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75)
184 define i32 @test74(i32 %x) {
185 ; CHECK-LABEL: @test74(
186 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i32 %x, 75
187 ; CHECK-NEXT:    [[RETVAL:%.*]] = select i1 [[TMP1]], i32 %x, i32 75, !prof ![[$MD4]]
188 ; CHECK-NEXT:    ret i32 [[RETVAL]]
189 ;
190   %cmp = icmp slt i32 %x, 36
191   %cond = select i1 %cmp, i32 36, i32 %x, !prof !1
192   %cmp3 = icmp slt i32 %cond, 75
193   %retval = select i1 %cmp3, i32 75, i32 %cond, !prof !2
194   ret i32 %retval
195 }
196
197 ; The compare should change, but the metadata remains the same because the select operands are not swapped.
198 define i32 @smin1(i32 %x) {
199 ; CHECK-LABEL: @smin1(
200 ; CHECK-NEXT:    [[NOT_X:%.*]] = xor i32 %x, -1
201 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[NOT_X]], -1
202 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 [[NOT_X]], i32 -1, !prof ![[$MD1]]
203 ; CHECK-NEXT:    ret i32 [[SEL]]
204 ;
205   %not_x = xor i32 %x, -1
206   %cmp = icmp sgt i32 %x, 0
207   %sel = select i1 %cmp, i32 %not_x, i32 -1, !prof !1
208   ret i32 %sel
209 }
210
211 ; The compare should change, and the metadata is swapped because the select operands are swapped.
212 define i32 @smin2(i32 %x) {
213 ; CHECK-LABEL: @smin2(
214 ; CHECK-NEXT:    [[NOT_X:%.*]] = xor i32 %x, -1
215 ; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[NOT_X]], -1
216 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 [[NOT_X]], i32 -1, !prof ![[$MD3]]
217 ; CHECK-NEXT:    ret i32 [[SEL]]
218 ;
219   %not_x = xor i32 %x, -1
220   %cmp = icmp slt i32 %x, 0
221   %sel = select i1 %cmp, i32 -1, i32 %not_x, !prof !1
222   ret i32 %sel
223 }
224
225 ; The compare should change, but the metadata remains the same because the select operands are not swapped.
226 define i32 @smax1(i32 %x) {
227 ; CHECK-LABEL: @smax1(
228 ; CHECK-NEXT:    [[NOT_X:%.*]] = xor i32 %x, -1
229 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[NOT_X]], -1
230 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 [[NOT_X]], i32 -1, !prof ![[$MD1]]
231 ; CHECK-NEXT:    ret i32 [[SEL]]
232 ;
233   %not_x = xor i32 %x, -1
234   %cmp = icmp slt i32 %x, 0
235   %sel = select i1 %cmp, i32 %not_x, i32 -1, !prof !1
236   ret i32 %sel
237 }
238
239 ; The compare should change, and the metadata is swapped because the select operands are swapped.
240 define i32 @smax2(i32 %x) {
241 ; CHECK-LABEL: @smax2(
242 ; CHECK-NEXT:    [[NOT_X:%.*]] = xor i32 %x, -1
243 ; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[NOT_X]], -1
244 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 [[NOT_X]], i32 -1, !prof ![[$MD3]]
245 ; CHECK-NEXT:    ret i32 [[SEL]]
246 ;
247   %not_x = xor i32 %x, -1
248   %cmp = icmp sgt i32 %x, 0
249   %sel = select i1 %cmp, i32 -1, i32 %not_x, !prof !1
250   ret i32 %sel
251 }
252
253 ; The compare should change, but the metadata remains the same because the select operands are not swapped.
254 define i32 @umin1(i32 %x) {
255 ; CHECK-LABEL: @umin1(
256 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i32 %x, -2147483648
257 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 -2147483648, !prof ![[$MD1]]
258 ; CHECK-NEXT:    ret i32 [[SEL]]
259 ;
260   %cmp = icmp sgt i32 %x, -1
261   %sel = select i1 %cmp, i32 %x, i32 -2147483648, !prof !1
262   ret i32 %sel
263 }
264
265 ; The compare should change, and the metadata is swapped because the select operands are swapped.
266 define i32 @umin2(i32 %x) {
267 ; CHECK-LABEL: @umin2(
268 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i32 %x, 2147483647
269 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 2147483647, !prof ![[$MD3]]
270 ; CHECK-NEXT:    ret i32 [[SEL]]
271 ;
272   %cmp = icmp slt i32 %x, 0
273   %sel = select i1 %cmp, i32 2147483647, i32 %x, !prof !1
274   ret i32 %sel
275 }
276
277 ; The compare should change, but the metadata remains the same because the select operands are not swapped.
278 define i32 @umax1(i32 %x) {
279 ; CHECK-LABEL: @umax1(
280 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i32 %x, 2147483647
281 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 2147483647, !prof ![[$MD1]]
282 ; CHECK-NEXT:    ret i32 [[SEL]]
283 ;
284   %cmp = icmp slt i32 %x, 0
285   %sel = select i1 %cmp, i32 %x, i32 2147483647, !prof !1
286   ret i32 %sel
287 }
288
289 ; The compare should change, and the metadata is swapped because the select operands are swapped.
290 define i32 @umax2(i32 %x) {
291 ; CHECK-LABEL: @umax2(
292 ; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i32 %x, -2147483648
293 ; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i32 %x, i32 -2147483648, !prof ![[$MD3]]
294 ; CHECK-NEXT:    ret i32 [[SEL]]
295 ;
296   %cmp = icmp sgt i32 %x, -1
297   %sel = select i1 %cmp, i32 -2147483648, i32 %x, !prof !1
298   ret i32 %sel
299 }
300
301 !1 = !{!"branch_weights", i32 2, i32 10}
302 !2 = !{!"branch_weights", i32 3, i32 10}
303
304 ; CHECK-DAG: ![[$MD1]] = !{!"branch_weights", i32 2, i32 10}
305 ; CHECK-DAG: ![[$MD3]] = !{!"branch_weights", i32 10, i32 2}
306 ; CHECK-DAG: ![[$MD4]] = !{!"branch_weights", i32 10, i32 3}
307