1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instsimplify -S < %s | FileCheck %s
4 declare float @llvm.minnum.f32(float, float)
5 declare bfloat @llvm.minnum.bf16(bfloat, bfloat)
6 declare half @llvm.minnum.f16(half, half)
7 declare <4 x float> @llvm.minnum.v4f32(<4 x float>, <4 x float>)
8 declare <4 x bfloat> @llvm.minnum.v4bf16(<4 x bfloat>, <4 x bfloat>)
9 declare <4 x half> @llvm.minnum.v4f16(<4 x half>, <4 x half>)
11 declare float @llvm.maxnum.f32(float, float)
12 declare bfloat @llvm.maxnum.bf16(bfloat, bfloat)
13 declare half @llvm.maxnum.f16(half, half)
14 declare <4 x float> @llvm.maxnum.v4f32(<4 x float>, <4 x float>)
15 declare <4 x bfloat> @llvm.maxnum.v4bf16(<4 x bfloat>, <4 x bfloat>)
16 declare <4 x half> @llvm.maxnum.v4f16(<4 x half>, <4 x half>)
18 declare float @llvm.minimum.f32(float, float)
19 declare bfloat @llvm.minimum.bf16(bfloat, bfloat)
20 declare half @llvm.minimum.f16(half, half)
21 declare <4 x float> @llvm.minimum.v4f32(<4 x float>, <4 x float>)
22 declare <4 x bfloat> @llvm.minimum.v4bf16(<4 x bfloat>, <4 x bfloat>)
23 declare <4 x half> @llvm.minimum.v4f16(<4 x half>, <4 x half>)
25 declare float @llvm.maximum.f32(float, float)
26 declare bfloat @llvm.maximum.bf16(bfloat, bfloat)
27 declare half @llvm.maximum.f16(half, half)
28 declare <4 x float> @llvm.maximum.v4f32(<4 x float>, <4 x float>)
29 declare <4 x bfloat> @llvm.maximum.v4bf16(<4 x bfloat>, <4 x bfloat>)
30 declare <4 x half> @llvm.maximum.v4f16(<4 x half>, <4 x half>)
32 declare i8 @llvm.smax.i8(i8, i8)
33 declare <5 x i8> @llvm.smax.v5i8(<5 x i8>, <5 x i8>)
35 declare i8 @llvm.smin.i8(i8, i8)
36 declare <5 x i8> @llvm.smin.v5i8(<5 x i8>, <5 x i8>)
38 declare i8 @llvm.umax.i8(i8, i8)
39 declare <5 x i8> @llvm.umax.v5i8(<5 x i8>, <5 x i8>)
41 declare i8 @llvm.umin.i8(i8, i8)
42 declare <5 x i8> @llvm.umin.v5i8(<5 x i8>, <5 x i8>)
44 define float @minnum_float() {
45 ; CHECK-LABEL: @minnum_float(
46 ; CHECK-NEXT: ret float 5.000000e+00
48 %1 = call float @llvm.minnum.f32(float 5.0, float 42.0)
52 define float @minnum_float_p0_n0() {
53 ; CHECK-LABEL: @minnum_float_p0_n0(
54 ; CHECK-NEXT: ret float -0.000000e+00
56 %min = call float @llvm.minnum.f32(float 0.0, float -0.0)
60 define float @minnum_float_n0_p0() {
61 ; CHECK-LABEL: @minnum_float_n0_p0(
62 ; CHECK-NEXT: ret float -0.000000e+00
64 %min = call float @llvm.minnum.f32(float -0.0, float 0.0)
68 define float @minnum_float_p0_qnan() {
69 ; CHECK-LABEL: @minnum_float_p0_qnan(
70 ; CHECK-NEXT: ret float 0.000000e+00
72 %min = call float @llvm.minnum.f32(float 0.0, float 0x7FF8000000000000)
76 define float @minnum_float_qnan_p0() {
77 ; CHECK-LABEL: @minnum_float_qnan_p0(
78 ; CHECK-NEXT: ret float 0.000000e+00
80 %min = call float @llvm.minnum.f32(float 0x7FF8000000000000, float 0.0)
84 define bfloat @minnum_bfloat() {
85 ; CHECK-LABEL: @minnum_bfloat(
86 ; CHECK-NEXT: ret bfloat 0xR40A0
88 %1 = call bfloat @llvm.minnum.bf16(bfloat 5.0, bfloat 42.0)
92 define half @minnum_half() {
93 ; CHECK-LABEL: @minnum_half(
94 ; CHECK-NEXT: ret half 0xH4500
96 %1 = call half @llvm.minnum.f16(half 5.0, half 42.0)
100 ; Check that minnum constant folds to propagate non-NaN or smaller argument
102 define <4 x float> @minnum_float_vec() {
103 ; CHECK-LABEL: @minnum_float_vec(
104 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 5.000000e+00, float 4.200000e+01, float 5.000000e+00>
106 %1 = call <4 x float> @llvm.minnum.v4f32(<4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>, <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>)
110 define <4 x bfloat> @minnum_bfloat_vec() {
111 ; CHECK-LABEL: @minnum_bfloat_vec(
112 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR40A0, bfloat 0xR4228, bfloat 0xR40A0>
114 %1 = call <4 x bfloat> @llvm.minnum.v4bf16(<4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 0x7FF8000000000000, bfloat 42., bfloat 42.>, <4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 5., bfloat 0x7FF8000000000000, bfloat 5.>)
118 define <4 x half> @minnum_half_vec() {
119 ; CHECK-LABEL: @minnum_half_vec(
120 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH4500, half 0xH5140, half 0xH4500>
122 %1 = call <4 x half> @llvm.minnum.v4f16(<4 x half> <half 0x7FF8000000000000, half 0x7FF8000000000000, half 42., half 42.>, <4 x half> <half 0x7FF8000000000000, half 5., half 0x7FF8000000000000, half 5.>)
126 ; Check that minnum constant folds to propagate one of its argument zeros
128 define <4 x float> @minnum_float_zeros_vec() {
129 ; CHECK-LABEL: @minnum_float_zeros_vec(
130 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>
132 %1 = call <4 x float> @llvm.minnum.v4f32(<4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>, <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>)
136 define float @maxnum_float() {
137 ; CHECK-LABEL: @maxnum_float(
138 ; CHECK-NEXT: ret float 4.200000e+01
140 %1 = call float @llvm.maxnum.f32(float 5.0, float 42.0)
144 define float @maxnum_float_p0_n0() {
145 ; CHECK-LABEL: @maxnum_float_p0_n0(
146 ; CHECK-NEXT: ret float 0.000000e+00
148 %max = call float @llvm.maxnum.f32(float 0.0, float -0.0)
152 define float @maxnum_float_n0_p0() {
153 ; CHECK-LABEL: @maxnum_float_n0_p0(
154 ; CHECK-NEXT: ret float 0.000000e+00
156 %max = call float @llvm.maxnum.f32(float -0.0, float 0.0)
160 define float @maxnum_float_p0_qnan() {
161 ; CHECK-LABEL: @maxnum_float_p0_qnan(
162 ; CHECK-NEXT: ret float 0.000000e+00
164 %max = call float @llvm.maxnum.f32(float 0.0, float 0x7FF8000000000000)
168 define float @maxnum_float_qnan_p0() {
169 ; CHECK-LABEL: @maxnum_float_qnan_p0(
170 ; CHECK-NEXT: ret float 0.000000e+00
172 %max = call float @llvm.maxnum.f32(float 0x7FF8000000000000, float 0.0)
176 define bfloat @maxnum_bfloat() {
177 ; CHECK-LABEL: @maxnum_bfloat(
178 ; CHECK-NEXT: ret bfloat 0xR4228
180 %1 = call bfloat @llvm.maxnum.bf16(bfloat 5.0, bfloat 42.0)
184 define half @maxnum_half() {
185 ; CHECK-LABEL: @maxnum_half(
186 ; CHECK-NEXT: ret half 0xH5140
188 %1 = call half @llvm.maxnum.f16(half 5.0, half 42.0)
192 ; Check that maxnum constant folds to propagate non-NaN or greater argument
194 define <4 x float> @maxnum_float_vec() {
195 ; CHECK-LABEL: @maxnum_float_vec(
196 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 5.000000e+00, float 4.200000e+01, float 4.200000e+01>
198 %1 = call <4 x float> @llvm.maxnum.v4f32(<4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>, <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>)
202 define <4 x bfloat> @maxnum_bfloat_vec() {
203 ; CHECK-LABEL: @maxnum_bfloat_vec(
204 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR40A0, bfloat 0xR4228, bfloat 0xR4228>
206 %1 = call <4 x bfloat> @llvm.maxnum.v4bf16(<4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 0x7FF8000000000000, bfloat 42., bfloat 42.>, <4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 5., bfloat 0x7FF8000000000000, bfloat 5.>)
210 define <4 x half> @maxnum_half_vec() {
211 ; CHECK-LABEL: @maxnum_half_vec(
212 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH4500, half 0xH5140, half 0xH5140>
214 %1 = call <4 x half> @llvm.maxnum.v4f16(<4 x half> <half 0x7FF8000000000000, half 0x7FF8000000000000, half 42., half 42.>, <4 x half> <half 0x7FF8000000000000, half 5., half 0x7FF8000000000000, half 5.>)
218 ; Check that maxnum constant folds to propagate one of its argument zeros
220 define <4 x float> @maxnum_float_zeros_vec() {
221 ; CHECK-LABEL: @maxnum_float_zeros_vec(
222 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float -0.000000e+00>
224 %1 = call <4 x float> @llvm.maxnum.v4f32(<4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>, <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>)
228 define float @minimum_float() {
229 ; CHECK-LABEL: @minimum_float(
230 ; CHECK-NEXT: ret float 5.000000e+00
232 %1 = call float @llvm.minimum.f32(float 5.0, float 42.0)
236 define bfloat @minimum_bfloat() {
237 ; CHECK-LABEL: @minimum_bfloat(
238 ; CHECK-NEXT: ret bfloat 0xR40A0
240 %1 = call bfloat @llvm.minimum.bf16(bfloat 5.0, bfloat 42.0)
244 define half @minimum_half() {
245 ; CHECK-LABEL: @minimum_half(
246 ; CHECK-NEXT: ret half 0xH4500
248 %1 = call half @llvm.minimum.f16(half 5.0, half 42.0)
252 ; Check that minimum propagates its NaN or smaller argument
254 define <4 x float> @minimum_float_vec() {
255 ; CHECK-LABEL: @minimum_float_vec(
256 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 0x7FF8000000000000, float 5.000000e+00>
258 %1 = call <4 x float> @llvm.minimum.v4f32(<4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>, <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>)
262 define <4 x bfloat> @minimum_bfloat_vec() {
263 ; CHECK-LABEL: @minimum_bfloat_vec(
264 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR40A0>
266 %1 = call <4 x bfloat> @llvm.minimum.v4bf16(<4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 0x7FF8000000000000, bfloat 42., bfloat 42.>, <4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 5., bfloat 0x7FF8000000000000, bfloat 5.>)
270 define <4 x half> @minimum_half_vec() {
271 ; CHECK-LABEL: @minimum_half_vec(
272 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH7E00, half 0xH7E00, half 0xH4500>
274 %1 = call <4 x half> @llvm.minimum.v4f16(<4 x half> <half 0x7FF8000000000000, half 0x7FF8000000000000, half 42., half 42.>, <4 x half> <half 0x7FF8000000000000, half 5., half 0x7FF8000000000000, half 5.>)
278 ; Check that minimum treats -0.0 as smaller than 0.0 while constant folding
280 define <4 x float> @minimum_float_zeros_vec() {
281 ; CHECK-LABEL: @minimum_float_zeros_vec(
282 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>
284 %1 = call <4 x float> @llvm.minimum.v4f32(<4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>, <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>)
288 define float @maximum_float() {
289 ; CHECK-LABEL: @maximum_float(
290 ; CHECK-NEXT: ret float 4.200000e+01
292 %1 = call float @llvm.maximum.f32(float 5.0, float 42.0)
296 define bfloat @maximum_bfloat() {
297 ; CHECK-LABEL: @maximum_bfloat(
298 ; CHECK-NEXT: ret bfloat 0xR4228
300 %1 = call bfloat @llvm.maximum.bf16(bfloat 5.0, bfloat 42.0)
304 define half @maximum_half() {
305 ; CHECK-LABEL: @maximum_half(
306 ; CHECK-NEXT: ret half 0xH5140
308 %1 = call half @llvm.maximum.f16(half 5.0, half 42.0)
312 ; Check that maximum propagates its NaN or greater argument
314 define <4 x float> @maximum_float_vec() {
315 ; CHECK-LABEL: @maximum_float_vec(
316 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 0x7FF8000000000000, float 4.200000e+01>
318 %1 = call <4 x float> @llvm.maximum.v4f32(<4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>, <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>)
322 define <4 x bfloat> @maximum_bfloat_vec() {
323 ; CHECK-LABEL: @maximum_bfloat_vec(
324 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR4228>
326 %1 = call <4 x bfloat> @llvm.maximum.v4bf16(<4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 0x7FF8000000000000, bfloat 42., bfloat 42.>, <4 x bfloat> <bfloat 0x7FF8000000000000, bfloat 5., bfloat 0x7FF8000000000000, bfloat 5.>)
330 define <4 x half> @maximum_half_vec() {
331 ; CHECK-LABEL: @maximum_half_vec(
332 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH7E00, half 0xH7E00, half 0xH5140>
334 %1 = call <4 x half> @llvm.maximum.v4f16(<4 x half> <half 0x7FF8000000000000, half 0x7FF8000000000000, half 42., half 42.>, <4 x half> <half 0x7FF8000000000000, half 5., half 0x7FF8000000000000, half 5.>)
338 ; Check that maximum treats -0.0 as smaller than 0.0 while constant folding
340 define <4 x float> @maximum_float_zeros_vec() {
341 ; CHECK-LABEL: @maximum_float_zeros_vec(
342 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float -0.000000e+00>
344 %1 = call <4 x float> @llvm.maximum.v4f32(<4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>, <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>)
349 ; CHECK-LABEL: @smax(
350 ; CHECK-NEXT: ret i8 -127
352 %r = call i8 @llvm.smax.i8(i8 128, i8 129)
356 define <5 x i8> @smax_vec() {
357 ; CHECK-LABEL: @smax_vec(
358 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 127, i8 poison, i8 42, i8 127>
360 %r = call <5 x i8> @llvm.smax.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 127>)
365 ; CHECK-LABEL: @smin(
366 ; CHECK-NEXT: ret i8 -128
368 %r = call i8 @llvm.smin.i8(i8 128, i8 127)
372 define <5 x i8> @smin_vec() {
373 ; CHECK-LABEL: @smin_vec(
374 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 -128, i8 poison, i8 42, i8 -127>
376 %r = call <5 x i8> @llvm.smin.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 129>)
381 ; CHECK-LABEL: @umax(
382 ; CHECK-NEXT: ret i8 -128
384 %r = call i8 @llvm.umax.i8(i8 128, i8 127)
388 define <5 x i8> @umax_vec() {
389 ; CHECK-LABEL: @umax_vec(
390 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 -1, i8 poison, i8 42, i8 -128>
392 %r = call <5 x i8> @llvm.umax.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 128>)
397 ; CHECK-LABEL: @umin(
398 ; CHECK-NEXT: ret i8 127
400 %r = call i8 @llvm.umin.i8(i8 128, i8 127)
404 define <5 x i8> @umin_vec() {
405 ; CHECK-LABEL: @umin_vec(
406 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 0, i8 poison, i8 42, i8 42>
408 %r = call <5 x i8> @llvm.umin.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 128>)