1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; (X < C1) ? C1 : MIN(X, C2)
5 define float @clamp_float_fast_ordered_strict_maxmin(float %x) {
6 ; CHECK-LABEL: @clamp_float_fast_ordered_strict_maxmin(
7 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
8 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
9 ; CHECK-NEXT: [[R1:%.*]] = call fast float @llvm.maxnum.f32(float [[MIN]], float 1.000000e+00)
10 ; CHECK-NEXT: ret float [[R1]]
12 %cmp2 = fcmp fast olt float %x, 255.0
13 %min = select i1 %cmp2, float %x, float 255.0
14 %cmp1 = fcmp fast olt float %x, 1.0
15 %r = select i1 %cmp1, float 1.0, float %min
19 ; (X <= C1) ? C1 : MIN(X, C2)
20 define float @clamp_float_fast_ordered_nonstrict_maxmin(float %x) {
21 ; CHECK-LABEL: @clamp_float_fast_ordered_nonstrict_maxmin(
22 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
23 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
24 ; CHECK-NEXT: [[R1:%.*]] = call fast float @llvm.maxnum.f32(float [[MIN]], float 1.000000e+00)
25 ; CHECK-NEXT: ret float [[R1]]
27 %cmp2 = fcmp fast olt float %x, 255.0
28 %min = select i1 %cmp2, float %x, float 255.0
29 %cmp1 = fcmp fast ole float %x, 1.0
30 %r = select i1 %cmp1, float 1.0, float %min
34 ; (X > C1) ? C1 : MAX(X, C2)
35 define float @clamp_float_fast_ordered_strict_minmax(float %x) {
36 ; CHECK-LABEL: @clamp_float_fast_ordered_strict_minmax(
37 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+00
38 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
39 ; CHECK-NEXT: [[R1:%.*]] = call fast float @llvm.minnum.f32(float [[MAX]], float 2.550000e+02)
40 ; CHECK-NEXT: ret float [[R1]]
42 %cmp2 = fcmp fast ogt float %x, 1.0
43 %max = select i1 %cmp2, float %x, float 1.0
44 %cmp1 = fcmp fast ogt float %x, 255.0
45 %r = select i1 %cmp1, float 255.0, float %max
49 ; (X >= C1) ? C1 : MAX(X, C2)
50 define float @clamp_float_fast_ordered_nonstrict_minmax(float %x) {
51 ; CHECK-LABEL: @clamp_float_fast_ordered_nonstrict_minmax(
52 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+00
53 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
54 ; CHECK-NEXT: [[R1:%.*]] = call fast float @llvm.minnum.f32(float [[MAX]], float 2.550000e+02)
55 ; CHECK-NEXT: ret float [[R1]]
57 %cmp2 = fcmp fast ogt float %x, 1.0
58 %max = select i1 %cmp2, float %x, float 1.0
59 %cmp1 = fcmp fast oge float %x, 255.0
60 %r = select i1 %cmp1, float 255.0, float %max
65 ; The same for unordered
67 ; (X < C1) ? C1 : MIN(X, C2)
68 define float @clamp_float_fast_unordered_strict_maxmin(float %x) {
69 ; CHECK-LABEL: @clamp_float_fast_unordered_strict_maxmin(
70 ; CHECK-NEXT: [[MIN:%.*]] = call fast float @llvm.minnum.f32(float [[X:%.*]], float 2.550000e+02)
71 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp fast ult float [[X]], 1.000000e+00
72 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
73 ; CHECK-NEXT: ret float [[R]]
75 %cmp2 = fcmp fast ult float %x, 255.0
76 %min = select i1 %cmp2, float %x, float 255.0
77 %cmp1 = fcmp fast ult float %x, 1.0
78 %r = select i1 %cmp1, float 1.0, float %min
82 ; (X <= C1) ? C1 : MIN(X, C2)
83 define float @clamp_float_fast_unordered_nonstrict_maxmin(float %x) {
84 ; CHECK-LABEL: @clamp_float_fast_unordered_nonstrict_maxmin(
85 ; CHECK-NEXT: [[MIN:%.*]] = call fast float @llvm.minnum.f32(float [[X:%.*]], float 2.550000e+02)
86 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp fast ule float [[X]], 1.000000e+00
87 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
88 ; CHECK-NEXT: ret float [[R]]
90 %cmp2 = fcmp fast ult float %x, 255.0
91 %min = select i1 %cmp2, float %x, float 255.0
92 %cmp1 = fcmp fast ule float %x, 1.0
93 %r = select i1 %cmp1, float 1.0, float %min
97 ; (X > C1) ? C1 : MAX(X, C2)
98 define float @clamp_float_fast_unordered_strict_minmax(float %x) {
99 ; CHECK-LABEL: @clamp_float_fast_unordered_strict_minmax(
100 ; CHECK-NEXT: [[MAX:%.*]] = call fast float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
101 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp fast ugt float [[X]], 2.550000e+02
102 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
103 ; CHECK-NEXT: ret float [[R]]
105 %cmp2 = fcmp fast ugt float %x, 1.0
106 %max = select i1 %cmp2, float %x, float 1.0
107 %cmp1 = fcmp fast ugt float %x, 255.0
108 %r = select i1 %cmp1, float 255.0, float %max
112 ; (X >= C1) ? C1 : MAX(X, C2)
113 define float @clamp_float_fast_unordered_nonstrict_minmax(float %x) {
114 ; CHECK-LABEL: @clamp_float_fast_unordered_nonstrict_minmax(
115 ; CHECK-NEXT: [[MAX:%.*]] = call fast float @llvm.maxnum.f32(float [[X:%.*]], float 1.000000e+00)
116 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp fast uge float [[X]], 2.550000e+02
117 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
118 ; CHECK-NEXT: ret float [[R]]
120 %cmp2 = fcmp fast ugt float %x, 1.0
121 %max = select i1 %cmp2, float %x, float 1.0
122 %cmp1 = fcmp fast uge float %x, 255.0
123 %r = select i1 %cmp1, float 255.0, float %max
127 ; Some more checks with fast
129 ; (X > 1.0) ? min(x, 255.0) : 1.0
130 define float @clamp_test_1(float %x) {
131 ; CHECK-LABEL: @clamp_test_1(
132 ; CHECK-NEXT: [[INNER_SEL:%.*]] = call fast float @llvm.minnum.f32(float [[X:%.*]], float 2.550000e+02)
133 ; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ugt float [[X]], 1.000000e+00
134 ; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[INNER_SEL]], float 1.000000e+00
135 ; CHECK-NEXT: ret float [[R]]
137 %inner_cmp = fcmp fast ult float %x, 255.0
138 %inner_sel = select i1 %inner_cmp, float %x, float 255.0
139 %outer_cmp = fcmp fast ugt float %x, 1.0
140 %r = select i1 %outer_cmp, float %inner_sel, float 1.0
144 ; And something negative
146 ; Like @clamp_test_1 but HighConst < LowConst
147 define float @clamp_negative_wrong_const(float %x) {
148 ; CHECK-LABEL: @clamp_negative_wrong_const(
149 ; CHECK-NEXT: [[INNER_SEL:%.*]] = call fast float @llvm.minnum.f32(float [[X:%.*]], float 2.550000e+02)
150 ; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ugt float [[X]], 5.120000e+02
151 ; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[INNER_SEL]], float 5.120000e+02
152 ; CHECK-NEXT: ret float [[R]]
154 %inner_cmp = fcmp fast ult float %x, 255.0
155 %inner_sel = select i1 %inner_cmp, float %x, float 255.0
156 %outer_cmp = fcmp fast ugt float %x, 512.0
157 %r = select i1 %outer_cmp, float %inner_sel, float 512.0
161 ; Like @clamp_test_1 but both are min
162 define float @clamp_negative_same_op(float %x) {
163 ; CHECK-LABEL: @clamp_negative_same_op(
164 ; CHECK-NEXT: [[INNER_SEL:%.*]] = call fast float @llvm.minnum.f32(float [[X:%.*]], float 2.550000e+02)
165 ; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ult float [[X]], 1.000000e+00
166 ; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[INNER_SEL]], float 1.000000e+00
167 ; CHECK-NEXT: ret float [[R]]
169 %inner_cmp = fcmp fast ult float %x, 255.0
170 %inner_sel = select i1 %inner_cmp, float %x, float 255.0
171 %outer_cmp = fcmp fast ult float %x, 1.0
172 %r = select i1 %outer_cmp, float %inner_sel, float 1.0
177 ; And now without fast.
179 ; First, check that we don't do bad things in the presence of signed zeros
180 define float @clamp_float_with_zero1(float %x) {
181 ; CHECK-LABEL: @clamp_float_with_zero1(
182 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
183 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
184 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ole float [[X]], 0.000000e+00
185 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float [[MIN]]
186 ; CHECK-NEXT: ret float [[R]]
188 %cmp2 = fcmp fast olt float %x, 255.0
189 %min = select i1 %cmp2, float %x, float 255.0
190 %cmp1 = fcmp ole float %x, 0.0
191 %r = select i1 %cmp1, float 0.0, float %min
195 define float @clamp_float_with_zero2(float %x) {
196 ; CHECK-LABEL: @clamp_float_with_zero2(
197 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
198 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
199 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp olt float [[X]], 0.000000e+00
200 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float [[MIN]]
201 ; CHECK-NEXT: ret float [[R]]
203 %cmp2 = fcmp fast olt float %x, 255.0
204 %min = select i1 %cmp2, float %x, float 255.0
205 %cmp1 = fcmp olt float %x, 0.0
206 %r = select i1 %cmp1, float 0.0, float %min
210 ; Also, here we care more about the ordering of the inner min/max, so
211 ; two times more cases.
212 ; TODO: that is not implemented yet, so these checks are for the
213 ; future. This means that checks below can just check that
214 ; "fcmp.*%x" happens twice for each label.
216 ; (X < C1) ? C1 : MIN(X, C2)
217 define float @clamp_float_ordered_strict_maxmin1(float %x) {
218 ; CHECK-LABEL: @clamp_float_ordered_strict_maxmin1(
219 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
220 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
221 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00
222 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
223 ; CHECK-NEXT: ret float [[R]]
225 %cmp2 = fcmp olt float %x, 255.0 ; X is NaN => false
226 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
227 %cmp1 = fcmp olt float %x, 1.0 ; false
228 %r = select i1 %cmp1, float 1.0, float %min ; min (255.0)
232 define float @clamp_float_ordered_strict_maxmin2(float %x) {
233 ; CHECK-LABEL: @clamp_float_ordered_strict_maxmin2(
234 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
235 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
236 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00
237 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
238 ; CHECK-NEXT: ret float [[R]]
240 %cmp2 = fcmp ult float %x, 255.0 ; X is NaN => true
241 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
242 %cmp1 = fcmp olt float %x, 1.0 ; false
243 %r = select i1 %cmp1, float 1.0, float %min ; min (NaN)
247 ; (X <= C1) ? C1 : MIN(X, C2)
248 define float @clamp_float_ordered_nonstrict_maxmin1(float %x) {
249 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin1(
250 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
251 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
252 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00
253 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
254 ; CHECK-NEXT: ret float [[R]]
256 %cmp2 = fcmp olt float %x, 255.0 ; X is NaN => false
257 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
258 %cmp1 = fcmp ole float %x, 1.0 ; false
259 %r = select i1 %cmp1, float 1.0, float %min ; min (255.0)
263 define float @clamp_float_ordered_nonstrict_maxmin2(float %x) {
264 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin2(
265 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
266 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
267 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00
268 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
269 ; CHECK-NEXT: ret float [[R]]
271 %cmp2 = fcmp ult float %x, 255.0 ; x is NaN => true
272 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
273 %cmp1 = fcmp ole float %x, 1.0 ; false
274 %r = select i1 %cmp1, float 1.0, float %min ; min (NaN)
278 ; (X > C1) ? C1 : MAX(X, C2)
279 define float @clamp_float_ordered_strict_minmax1(float %x) {
280 ; CHECK-LABEL: @clamp_float_ordered_strict_minmax1(
281 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
282 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
283 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02
284 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
285 ; CHECK-NEXT: ret float [[R]]
287 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
288 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
289 %cmp1 = fcmp ogt float %x, 255.0 ; false
290 %r = select i1 %cmp1, float 255.0, float %max ; max (1.0)
294 define float @clamp_float_ordered_strict_minmax2(float %x) {
295 ; CHECK-LABEL: @clamp_float_ordered_strict_minmax2(
296 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
297 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
298 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02
299 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
300 ; CHECK-NEXT: ret float [[R]]
302 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
303 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
304 %cmp1 = fcmp ogt float %x, 255.0 ; false
305 %r = select i1 %cmp1, float 255.0, float %max ; max (NaN)
309 ; (X >= C1) ? C1 : MAX(X, C2)
310 define float @clamp_float_ordered_nonstrict_minmax1(float %x) {
311 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax1(
312 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
313 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
314 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02
315 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
316 ; CHECK-NEXT: ret float [[R]]
318 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
319 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
320 %cmp1 = fcmp oge float %x, 255.0 ; false
321 %r = select i1 %cmp1, float 255.0, float %max ; max (1.0)
325 define float @clamp_float_ordered_nonstrict_minmax2(float %x) {
326 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax2(
327 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
328 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
329 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02
330 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
331 ; CHECK-NEXT: ret float [[R]]
333 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
334 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
335 %cmp1 = fcmp oge float %x, 255.0 ; false
336 %r = select i1 %cmp1, float 255.0, float %max ; max (NaN)
341 ; The same for unordered
343 ; (X < C1) ? C1 : MIN(X, C2)
344 define float @clamp_float_unordered_strict_maxmin1(float %x) {
345 ; CHECK-LABEL: @clamp_float_unordered_strict_maxmin1(
346 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
347 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
348 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00
349 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
350 ; CHECK-NEXT: ret float [[R]]
352 %cmp2 = fcmp olt float %x, 255.0 ; x is NaN => false
353 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
354 %cmp1 = fcmp ult float %x, 1.0 ; true
355 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
359 define float @clamp_float_unordered_strict_maxmin2(float %x) {
360 ; CHECK-LABEL: @clamp_float_unordered_strict_maxmin2(
361 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
362 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
363 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00
364 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
365 ; CHECK-NEXT: ret float [[R]]
367 %cmp2 = fcmp ult float %x, 255.0 ; x is NaN => true
368 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
369 %cmp1 = fcmp ult float %x, 1.0 ; true
370 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
374 ; (X <= C1) ? C1 : MIN(X, C2)
375 define float @clamp_float_unordered_nonstrict_maxmin1(float %x) {
376 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin1(
377 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
378 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
379 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00
380 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
381 ; CHECK-NEXT: ret float [[R]]
383 %cmp2 = fcmp olt float %x, 255.0 ; x is NaN => false
384 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
385 %cmp1 = fcmp ule float %x, 1.0 ; true
386 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
390 define float @clamp_float_unordered_nonstrict_maxmin2(float %x) {
391 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin2(
392 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
393 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
394 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00
395 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
396 ; CHECK-NEXT: ret float [[R]]
398 %cmp2 = fcmp ult float %x, 255.0 ; x is NaN => true
399 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
400 %cmp1 = fcmp ule float %x, 1.0 ; true
401 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
405 ; (X > C1) ? C1 : MAX(X, C2)
406 define float @clamp_float_unordered_strict_minmax1(float %x) {
407 ; CHECK-LABEL: @clamp_float_unordered_strict_minmax1(
408 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
409 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
410 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02
411 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
412 ; CHECK-NEXT: ret float [[R]]
414 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
415 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
416 %cmp1 = fcmp ugt float %x, 255.0 ; true
417 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
421 define float @clamp_float_unordered_strict_minmax2(float %x) {
422 ; CHECK-LABEL: @clamp_float_unordered_strict_minmax2(
423 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
424 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
425 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02
426 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
427 ; CHECK-NEXT: ret float [[R]]
429 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
430 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
431 %cmp1 = fcmp ugt float %x, 255.0 ; true
432 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
436 ; (X >= C1) ? C1 : MAX(X, C2)
437 define float @clamp_float_unordered_nonstrict_minmax1(float %x) {
438 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax1(
439 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
440 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
441 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02
442 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
443 ; CHECK-NEXT: ret float [[R]]
445 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
446 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
447 %cmp1 = fcmp uge float %x, 255.0 ; true
448 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
452 define float @clamp_float_unordered_nonstrict_minmax2(float %x) {
453 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax2(
454 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
455 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
456 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02
457 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
458 ; CHECK-NEXT: ret float [[R]]
460 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
461 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
462 %cmp1 = fcmp uge float %x, 255.0 ; true
463 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
467 ;; Check casts behavior
468 define float @ui32_clamp_and_cast_to_float(i32 %x) {
469 ; CHECK-LABEL: @ui32_clamp_and_cast_to_float(
470 ; CHECK-NEXT: [[LO_CMP:%.*]] = icmp eq i32 [[X:%.*]], 0
471 ; CHECK-NEXT: [[MIN1:%.*]] = call i32 @llvm.umin.i32(i32 [[X]], i32 255)
472 ; CHECK-NEXT: [[MIN:%.*]] = uitofp nneg i32 [[MIN1]] to float
473 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], float 1.000000e+00, float [[MIN]]
474 ; CHECK-NEXT: ret float [[R]]
476 %f_x = uitofp i32 %x to float
477 %up_cmp = icmp ugt i32 %x, 255
478 %lo_cmp = icmp ult i32 %x, 1
479 %min = select i1 %up_cmp, float 255.0, float %f_x
480 %r = select i1 %lo_cmp, float 1.0, float %min
484 define float @ui64_clamp_and_cast_to_float(i64 %x) {
485 ; CHECK-LABEL: @ui64_clamp_and_cast_to_float(
486 ; CHECK-NEXT: [[LO_CMP:%.*]] = icmp eq i64 [[X:%.*]], 0
487 ; CHECK-NEXT: [[MIN1:%.*]] = call i64 @llvm.umin.i64(i64 [[X]], i64 255)
488 ; CHECK-NEXT: [[MIN:%.*]] = uitofp nneg i64 [[MIN1]] to float
489 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], float 1.000000e+00, float [[MIN]]
490 ; CHECK-NEXT: ret float [[R]]
492 %f_x = uitofp i64 %x to float
493 %up_cmp = icmp ugt i64 %x, 255
494 %lo_cmp = icmp ult i64 %x, 1
495 %min = select i1 %up_cmp, float 255.0, float %f_x
496 %r = select i1 %lo_cmp, float 1.0, float %min
500 define float @mixed_clamp_to_float_1(i32 %x) {
501 ; CHECK-LABEL: @mixed_clamp_to_float_1(
502 ; CHECK-NEXT: [[SI_MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 255)
503 ; CHECK-NEXT: [[R1:%.*]] = call i32 @llvm.smax.i32(i32 [[SI_MIN]], i32 1)
504 ; CHECK-NEXT: [[R:%.*]] = uitofp nneg i32 [[R1]] to float
505 ; CHECK-NEXT: ret float [[R]]
507 %si_min_cmp = icmp sgt i32 %x, 255
508 %si_min = select i1 %si_min_cmp, i32 255, i32 %x
509 %f_min = sitofp i32 %si_min to float
510 %f_x = sitofp i32 %x to float
511 %lo_cmp = fcmp ult float %f_x, 1.0
512 %r = select i1 %lo_cmp, float 1.0, float %f_min
516 define i32 @mixed_clamp_to_i32_1(float %x) {
517 ; CHECK-LABEL: @mixed_clamp_to_i32_1(
518 ; CHECK-NEXT: [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02
519 ; CHECK-NEXT: [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 2.550000e+02, float [[X]]
520 ; CHECK-NEXT: [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32
521 ; CHECK-NEXT: [[I32_X:%.*]] = fptosi float [[X]] to i32
522 ; CHECK-NEXT: [[LO_CMP:%.*]] = icmp eq i32 [[I32_X]], 0
523 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]
524 ; CHECK-NEXT: ret i32 [[R]]
526 %float_min_cmp = fcmp ogt float %x, 255.0
527 %float_min = select i1 %float_min_cmp, float 255.0, float %x
528 %i32_min = fptosi float %float_min to i32
529 %i32_x = fptosi float %x to i32
530 %lo_cmp = icmp ult i32 %i32_x, 1
531 %r = select i1 %lo_cmp, i32 1, i32 %i32_min
535 define float @mixed_clamp_to_float_2(i32 %x) {
536 ; CHECK-LABEL: @mixed_clamp_to_float_2(
537 ; CHECK-NEXT: [[SI_MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 255)
538 ; CHECK-NEXT: [[R1:%.*]] = call i32 @llvm.smax.i32(i32 [[SI_MIN]], i32 1)
539 ; CHECK-NEXT: [[R:%.*]] = uitofp nneg i32 [[R1]] to float
540 ; CHECK-NEXT: ret float [[R]]
542 %si_min_cmp = icmp sgt i32 %x, 255
543 %si_min = select i1 %si_min_cmp, i32 255, i32 %x
544 %f_min = sitofp i32 %si_min to float
545 %lo_cmp = icmp slt i32 %x, 1
546 %r = select i1 %lo_cmp, float 1.0, float %f_min
550 define i32 @mixed_clamp_to_i32_2(float %x) {
551 ; CHECK-LABEL: @mixed_clamp_to_i32_2(
552 ; CHECK-NEXT: [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02
553 ; CHECK-NEXT: [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 2.550000e+02, float [[X]]
554 ; CHECK-NEXT: [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32
555 ; CHECK-NEXT: [[LO_CMP:%.*]] = fcmp olt float [[X]], 1.000000e+00
556 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]
557 ; CHECK-NEXT: ret i32 [[R]]
559 %float_min_cmp = fcmp ogt float %x, 255.0
560 %float_min = select i1 %float_min_cmp, float 255.0, float %x
561 %i32_min = fptosi float %float_min to i32
562 %lo_cmp = fcmp olt float %x, 1.0
563 %r = select i1 %lo_cmp, i32 1, i32 %i32_min
568 define <2 x float> @mixed_clamp_to_float_vec(<2 x i32> %x) {
569 ; CHECK-LABEL: @mixed_clamp_to_float_vec(
570 ; CHECK-NEXT: [[SI_MIN:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[X:%.*]], <2 x i32> splat (i32 255))
571 ; CHECK-NEXT: [[R1:%.*]] = call <2 x i32> @llvm.smax.v2i32(<2 x i32> [[SI_MIN]], <2 x i32> splat (i32 1))
572 ; CHECK-NEXT: [[R:%.*]] = uitofp nneg <2 x i32> [[R1]] to <2 x float>
573 ; CHECK-NEXT: ret <2 x float> [[R]]
575 %si_min_cmp = icmp sgt <2 x i32> %x, <i32 255, i32 255>
576 %si_min = select <2 x i1> %si_min_cmp, <2 x i32> <i32 255, i32 255>, <2 x i32> %x
577 %f_min = sitofp <2 x i32> %si_min to <2 x float>
578 %f_x = sitofp <2 x i32> %x to <2 x float>
579 %lo_cmp = fcmp ult <2 x float> %f_x, <float 1.0, float 1.0>
580 %r = select <2 x i1> %lo_cmp, <2 x float> <float 1.0, float 1.0>, <2 x float> %f_min