1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[MIN]], float 1.000000e+00)
10 ; CHECK-NEXT: ret float [[TMP1]]
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: [[TMP1:%.*]] = call fast float @llvm.maxnum.f32(float [[MIN]], float 1.000000e+00)
25 ; CHECK-NEXT: ret float [[TMP1]]
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: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[MAX]], float 2.550000e+02)
40 ; CHECK-NEXT: ret float [[TMP1]]
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: [[TMP1:%.*]] = call fast float @llvm.minnum.f32(float [[MAX]], float 2.550000e+02)
55 ; CHECK-NEXT: ret float [[TMP1]]
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: [[CMP2_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
71 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
72 ; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.maxnum.f32(float [[TMP1]], float 1.000000e+00)
73 ; CHECK-NEXT: ret float [[TMP2]]
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: [[CMP2_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
86 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
87 ; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.maxnum.f32(float [[TMP1]], float 1.000000e+00)
88 ; CHECK-NEXT: ret float [[TMP2]]
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: [[CMP2_INV:%.*]] = fcmp fast ole float [[X:%.*]], 1.000000e+00
101 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
102 ; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.minnum.f32(float [[TMP1]], float 2.550000e+02)
103 ; CHECK-NEXT: ret float [[TMP2]]
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: [[CMP2_INV:%.*]] = fcmp fast ole float [[X:%.*]], 1.000000e+00
116 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
117 ; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.minnum.f32(float [[TMP1]], float 2.550000e+02)
118 ; CHECK-NEXT: ret float [[TMP2]]
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 ; That did not match because select was in inverse order.
131 define float @clamp_test_1(float %x) {
132 ; CHECK-LABEL: @clamp_test_1(
133 ; CHECK-NEXT: [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
134 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
135 ; CHECK-NEXT: [[TMP2:%.*]] = call fast float @llvm.maxnum.f32(float [[TMP1]], float 1.000000e+00)
136 ; CHECK-NEXT: ret float [[TMP2]]
138 %inner_cmp = fcmp fast ult float %x, 255.0
139 %inner_sel = select i1 %inner_cmp, float %x, float 255.0
140 %outer_cmp = fcmp fast ugt float %x, 1.0
141 %r = select i1 %outer_cmp, float %inner_sel, float 1.0
145 ; And something negative
147 ; Like @clamp_test_1 but HighConst < LowConst
148 define float @clamp_negative_wrong_const(float %x) {
149 ; CHECK-LABEL: @clamp_negative_wrong_const(
150 ; CHECK-NEXT: [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
151 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
152 ; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ugt float [[X]], 5.120000e+02
153 ; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[TMP1]], float 5.120000e+02
154 ; CHECK-NEXT: ret float [[R]]
156 %inner_cmp = fcmp fast ult float %x, 255.0
157 %inner_sel = select i1 %inner_cmp, float %x, float 255.0
158 %outer_cmp = fcmp fast ugt float %x, 512.0
159 %r = select i1 %outer_cmp, float %inner_sel, float 512.0
163 ; Like @clamp_test_1 but both are min
164 define float @clamp_negative_same_op(float %x) {
165 ; CHECK-LABEL: @clamp_negative_same_op(
166 ; CHECK-NEXT: [[INNER_CMP_INV:%.*]] = fcmp fast oge float [[X:%.*]], 2.550000e+02
167 ; CHECK-NEXT: [[TMP1:%.*]] = select fast i1 [[INNER_CMP_INV]], float 2.550000e+02, float [[X]]
168 ; CHECK-NEXT: [[OUTER_CMP:%.*]] = fcmp fast ult float [[X]], 1.000000e+00
169 ; CHECK-NEXT: [[R:%.*]] = select i1 [[OUTER_CMP]], float [[TMP1]], float 1.000000e+00
170 ; CHECK-NEXT: ret float [[R]]
172 %inner_cmp = fcmp fast ult float %x, 255.0
173 %inner_sel = select i1 %inner_cmp, float %x, float 255.0
174 %outer_cmp = fcmp fast ult float %x, 1.0
175 %r = select i1 %outer_cmp, float %inner_sel, float 1.0
180 ; And now without fast.
182 ; First, check that we don't do bad things in the presence of signed zeros
183 define float @clamp_float_with_zero1(float %x) {
184 ; CHECK-LABEL: @clamp_float_with_zero1(
185 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
186 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
187 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ole float [[X]], 0.000000e+00
188 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float [[MIN]]
189 ; CHECK-NEXT: ret float [[R]]
191 %cmp2 = fcmp fast olt float %x, 255.0
192 %min = select i1 %cmp2, float %x, float 255.0
193 %cmp1 = fcmp ole float %x, 0.0
194 %r = select i1 %cmp1, float 0.0, float %min
198 define float @clamp_float_with_zero2(float %x) {
199 ; CHECK-LABEL: @clamp_float_with_zero2(
200 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
201 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
202 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp olt float [[X]], 0.000000e+00
203 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float [[MIN]]
204 ; CHECK-NEXT: ret float [[R]]
206 %cmp2 = fcmp fast olt float %x, 255.0
207 %min = select i1 %cmp2, float %x, float 255.0
208 %cmp1 = fcmp olt float %x, 0.0
209 %r = select i1 %cmp1, float 0.0, float %min
213 ; Also, here we care more about the ordering of the inner min/max, so
214 ; two times more cases.
215 ; TODO: that is not implemented yet, so these checks are for the
216 ; future. This means that checks below can just check that
217 ; "fcmp.*%x" happens twice for each label.
219 ; (X < C1) ? C1 : MIN(X, C2)
220 define float @clamp_float_ordered_strict_maxmin1(float %x) {
221 ; CHECK-LABEL: @clamp_float_ordered_strict_maxmin1(
222 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
223 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
224 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00
225 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
226 ; CHECK-NEXT: ret float [[R]]
228 %cmp2 = fcmp olt float %x, 255.0 ; X is NaN => false
229 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
230 %cmp1 = fcmp olt float %x, 1.0 ; false
231 %r = select i1 %cmp1, float 1.0, float %min ; min (255.0)
235 define float @clamp_float_ordered_strict_maxmin2(float %x) {
236 ; CHECK-LABEL: @clamp_float_ordered_strict_maxmin2(
237 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
238 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
239 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00
240 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[TMP1]]
241 ; CHECK-NEXT: ret float [[R]]
243 %cmp2 = fcmp ult float %x, 255.0 ; X is NaN => true
244 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
245 %cmp1 = fcmp olt float %x, 1.0 ; false
246 %r = select i1 %cmp1, float 1.0, float %min ; min (NaN)
250 ; (X <= C1) ? C1 : MIN(X, C2)
251 define float @clamp_float_ordered_nonstrict_maxmin1(float %x) {
252 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin1(
253 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
254 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
255 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00
256 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
257 ; CHECK-NEXT: ret float [[R]]
259 %cmp2 = fcmp olt float %x, 255.0 ; X is NaN => false
260 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
261 %cmp1 = fcmp ole float %x, 1.0 ; false
262 %r = select i1 %cmp1, float 1.0, float %min ; min (255.0)
266 define float @clamp_float_ordered_nonstrict_maxmin2(float %x) {
267 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin2(
268 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
269 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
270 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00
271 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[TMP1]]
272 ; CHECK-NEXT: ret float [[R]]
274 %cmp2 = fcmp ult float %x, 255.0 ; x is NaN => true
275 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
276 %cmp1 = fcmp ole float %x, 1.0 ; false
277 %r = select i1 %cmp1, float 1.0, float %min ; min (NaN)
281 ; (X > C1) ? C1 : MAX(X, C2)
282 define float @clamp_float_ordered_strict_minmax1(float %x) {
283 ; CHECK-LABEL: @clamp_float_ordered_strict_minmax1(
284 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
285 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
286 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02
287 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
288 ; CHECK-NEXT: ret float [[R]]
290 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
291 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
292 %cmp1 = fcmp ogt float %x, 255.0 ; false
293 %r = select i1 %cmp1, float 255.0, float %max ; max (1.0)
297 define float @clamp_float_ordered_strict_minmax2(float %x) {
298 ; CHECK-LABEL: @clamp_float_ordered_strict_minmax2(
299 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
300 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
301 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02
302 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[TMP1]]
303 ; CHECK-NEXT: ret float [[R]]
305 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
306 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
307 %cmp1 = fcmp ogt float %x, 255.0 ; false
308 %r = select i1 %cmp1, float 255.0, float %max ; max (NaN)
312 ; (X >= C1) ? C1 : MAX(X, C2)
313 define float @clamp_float_ordered_nonstrict_minmax1(float %x) {
314 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax1(
315 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
316 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
317 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02
318 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
319 ; CHECK-NEXT: ret float [[R]]
321 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
322 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
323 %cmp1 = fcmp oge float %x, 255.0 ; false
324 %r = select i1 %cmp1, float 255.0, float %max ; max (1.0)
328 define float @clamp_float_ordered_nonstrict_minmax2(float %x) {
329 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax2(
330 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
331 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
332 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02
333 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[TMP1]]
334 ; CHECK-NEXT: ret float [[R]]
336 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
337 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
338 %cmp1 = fcmp oge float %x, 255.0 ; false
339 %r = select i1 %cmp1, float 255.0, float %max ; max (NaN)
344 ; The same for unordered
346 ; (X < C1) ? C1 : MIN(X, C2)
347 define float @clamp_float_unordered_strict_maxmin1(float %x) {
348 ; CHECK-LABEL: @clamp_float_unordered_strict_maxmin1(
349 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
350 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
351 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00
352 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
353 ; CHECK-NEXT: ret float [[R]]
355 %cmp2 = fcmp olt float %x, 255.0 ; x is NaN => false
356 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
357 %cmp1 = fcmp ult float %x, 1.0 ; true
358 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
362 define float @clamp_float_unordered_strict_maxmin2(float %x) {
363 ; CHECK-LABEL: @clamp_float_unordered_strict_maxmin2(
364 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
365 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
366 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00
367 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[TMP1]]
368 ; CHECK-NEXT: ret float [[R]]
370 %cmp2 = fcmp ult float %x, 255.0 ; x is NaN => true
371 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
372 %cmp1 = fcmp ult float %x, 1.0 ; true
373 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
377 ; (X <= C1) ? C1 : MIN(X, C2)
378 define float @clamp_float_unordered_nonstrict_maxmin1(float %x) {
379 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin1(
380 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
381 ; CHECK-NEXT: [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 2.550000e+02
382 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00
383 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[MIN]]
384 ; CHECK-NEXT: ret float [[R]]
386 %cmp2 = fcmp olt float %x, 255.0 ; x is NaN => false
387 %min = select i1 %cmp2, float %x, float 255.0 ; 255.0
388 %cmp1 = fcmp ule float %x, 1.0 ; true
389 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
393 define float @clamp_float_unordered_nonstrict_maxmin2(float %x) {
394 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin2(
395 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp oge float [[X:%.*]], 2.550000e+02
396 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 2.550000e+02, float [[X]]
397 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00
398 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float [[TMP1]]
399 ; CHECK-NEXT: ret float [[R]]
401 %cmp2 = fcmp ult float %x, 255.0 ; x is NaN => true
402 %min = select i1 %cmp2, float %x, float 255.0 ; NaN
403 %cmp1 = fcmp ule float %x, 1.0 ; true
404 %r = select i1 %cmp1, float 1.0, float %min ; 1.0
408 ; (X > C1) ? C1 : MAX(X, C2)
409 define float @clamp_float_unordered_strict_minmax1(float %x) {
410 ; CHECK-LABEL: @clamp_float_unordered_strict_minmax1(
411 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
412 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
413 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02
414 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
415 ; CHECK-NEXT: ret float [[R]]
417 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
418 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
419 %cmp1 = fcmp ugt float %x, 255.0 ; true
420 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
424 define float @clamp_float_unordered_strict_minmax2(float %x) {
425 ; CHECK-LABEL: @clamp_float_unordered_strict_minmax2(
426 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
427 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
428 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02
429 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[TMP1]]
430 ; CHECK-NEXT: ret float [[R]]
432 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
433 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
434 %cmp1 = fcmp ugt float %x, 255.0 ; true
435 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
439 ; (X >= C1) ? C1 : MAX(X, C2)
440 define float @clamp_float_unordered_nonstrict_minmax1(float %x) {
441 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax1(
442 ; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
443 ; CHECK-NEXT: [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 1.000000e+00
444 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02
445 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[MAX]]
446 ; CHECK-NEXT: ret float [[R]]
448 %cmp2 = fcmp ogt float %x, 1.0 ; x is NaN => false
449 %max = select i1 %cmp2, float %x, float 1.0 ; 1.0
450 %cmp1 = fcmp uge float %x, 255.0 ; true
451 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
455 define float @clamp_float_unordered_nonstrict_minmax2(float %x) {
456 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax2(
457 ; CHECK-NEXT: [[CMP2_INV:%.*]] = fcmp ole float [[X:%.*]], 1.000000e+00
458 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP2_INV]], float 1.000000e+00, float [[X]]
459 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02
460 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float [[TMP1]]
461 ; CHECK-NEXT: ret float [[R]]
463 %cmp2 = fcmp ugt float %x, 1.0 ; x is NaN => true
464 %max = select i1 %cmp2, float %x, float 1.0 ; NaN
465 %cmp1 = fcmp uge float %x, 255.0 ; true
466 %r = select i1 %cmp1, float 255.0, float %max ; 255.0
470 ;; Check casts behavior
471 define float @ui32_clamp_and_cast_to_float(i32 %x) {
472 ; CHECK-LABEL: @ui32_clamp_and_cast_to_float(
473 ; CHECK-NEXT: [[LO_CMP:%.*]] = icmp eq i32 [[X:%.*]], 0
474 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X]], 255
475 ; CHECK-NEXT: [[MIN1:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 255
476 ; CHECK-NEXT: [[TMP2:%.*]] = uitofp i32 [[MIN1]] to float
477 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], float 1.000000e+00, float [[TMP2]]
478 ; CHECK-NEXT: ret float [[R]]
480 %f_x = uitofp i32 %x to float
481 %up_cmp = icmp ugt i32 %x, 255
482 %lo_cmp = icmp ult i32 %x, 1
483 %min = select i1 %up_cmp, float 255.0, float %f_x
484 %r = select i1 %lo_cmp, float 1.0, float %min
488 define float @ui64_clamp_and_cast_to_float(i64 %x) {
489 ; CHECK-LABEL: @ui64_clamp_and_cast_to_float(
490 ; CHECK-NEXT: [[LO_CMP:%.*]] = icmp eq i64 [[X:%.*]], 0
491 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i64 [[X]], 255
492 ; CHECK-NEXT: [[MIN1:%.*]] = select i1 [[TMP1]], i64 [[X]], i64 255
493 ; CHECK-NEXT: [[TMP2:%.*]] = uitofp i64 [[MIN1]] to float
494 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], float 1.000000e+00, float [[TMP2]]
495 ; CHECK-NEXT: ret float [[R]]
497 %f_x = uitofp i64 %x to float
498 %up_cmp = icmp ugt i64 %x, 255
499 %lo_cmp = icmp ult i64 %x, 1
500 %min = select i1 %up_cmp, float 255.0, float %f_x
501 %r = select i1 %lo_cmp, float 1.0, float %min
505 define float @mixed_clamp_to_float_1(i32 %x) {
506 ; CHECK-LABEL: @mixed_clamp_to_float_1(
507 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 255
508 ; CHECK-NEXT: [[SI_MIN:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 255
509 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[SI_MIN]], 1
510 ; CHECK-NEXT: [[R1:%.*]] = select i1 [[TMP2]], i32 [[SI_MIN]], i32 1
511 ; CHECK-NEXT: [[TMP3:%.*]] = sitofp i32 [[R1]] to float
512 ; CHECK-NEXT: ret float [[TMP3]]
514 %si_min_cmp = icmp sgt i32 %x, 255
515 %si_min = select i1 %si_min_cmp, i32 255, i32 %x
516 %f_min = sitofp i32 %si_min to float
517 %f_x = sitofp i32 %x to float
518 %lo_cmp = fcmp ult float %f_x, 1.0
519 %r = select i1 %lo_cmp, float 1.0, float %f_min
523 define i32 @mixed_clamp_to_i32_1(float %x) {
524 ; CHECK-LABEL: @mixed_clamp_to_i32_1(
525 ; CHECK-NEXT: [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02
526 ; CHECK-NEXT: [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 2.550000e+02, float [[X]]
527 ; CHECK-NEXT: [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32
528 ; CHECK-NEXT: [[I32_X:%.*]] = fptosi float [[X]] to i32
529 ; CHECK-NEXT: [[LO_CMP:%.*]] = icmp eq i32 [[I32_X]], 0
530 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]
531 ; CHECK-NEXT: ret i32 [[R]]
533 %float_min_cmp = fcmp ogt float %x, 255.0
534 %float_min = select i1 %float_min_cmp, float 255.0, float %x
535 %i32_min = fptosi float %float_min to i32
536 %i32_x = fptosi float %x to i32
537 %lo_cmp = icmp ult i32 %i32_x, 1
538 %r = select i1 %lo_cmp, i32 1, i32 %i32_min
542 define float @mixed_clamp_to_float_2(i32 %x) {
543 ; CHECK-LABEL: @mixed_clamp_to_float_2(
544 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 255
545 ; CHECK-NEXT: [[SI_MIN:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 255
546 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[SI_MIN]], 1
547 ; CHECK-NEXT: [[R1:%.*]] = select i1 [[TMP2]], i32 [[SI_MIN]], i32 1
548 ; CHECK-NEXT: [[TMP3:%.*]] = sitofp i32 [[R1]] to float
549 ; CHECK-NEXT: ret float [[TMP3]]
551 %si_min_cmp = icmp sgt i32 %x, 255
552 %si_min = select i1 %si_min_cmp, i32 255, i32 %x
553 %f_min = sitofp i32 %si_min to float
554 %lo_cmp = icmp slt i32 %x, 1
555 %r = select i1 %lo_cmp, float 1.0, float %f_min
559 define i32 @mixed_clamp_to_i32_2(float %x) {
560 ; CHECK-LABEL: @mixed_clamp_to_i32_2(
561 ; CHECK-NEXT: [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02
562 ; CHECK-NEXT: [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 2.550000e+02, float [[X]]
563 ; CHECK-NEXT: [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32
564 ; CHECK-NEXT: [[LO_CMP:%.*]] = fcmp olt float [[X]], 1.000000e+00
565 ; CHECK-NEXT: [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]
566 ; CHECK-NEXT: ret i32 [[R]]
568 %float_min_cmp = fcmp ogt float %x, 255.0
569 %float_min = select i1 %float_min_cmp, float 255.0, float %x
570 %i32_min = fptosi float %float_min to i32
571 %lo_cmp = fcmp olt float %x, 1.0
572 %r = select i1 %lo_cmp, i32 1, i32 %i32_min