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 bfloat @minnum_bfloat() {
53 ; CHECK-LABEL: @minnum_bfloat(
54 ; CHECK-NEXT: ret bfloat 0xR40A0
56 %1 = call bfloat @llvm.minnum.bf16(bfloat 5.0, bfloat 42.0)
60 define half @minnum_half() {
61 ; CHECK-LABEL: @minnum_half(
62 ; CHECK-NEXT: ret half 0xH4500
64 %1 = call half @llvm.minnum.f16(half 5.0, half 42.0)
68 ; Check that minnum constant folds to propagate non-NaN or smaller argument
70 define <4 x float> @minnum_float_vec() {
71 ; CHECK-LABEL: @minnum_float_vec(
72 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 5.000000e+00, float 4.200000e+01, float 5.000000e+00>
74 %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.>)
78 define <4 x bfloat> @minnum_bfloat_vec() {
79 ; CHECK-LABEL: @minnum_bfloat_vec(
80 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR40A0, bfloat 0xR4228, bfloat 0xR40A0>
82 %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.>)
86 define <4 x half> @minnum_half_vec() {
87 ; CHECK-LABEL: @minnum_half_vec(
88 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH4500, half 0xH5140, half 0xH4500>
90 %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.>)
94 ; Check that minnum constant folds to propagate one of its argument zeros
96 define <4 x float> @minnum_float_zeros_vec() {
97 ; CHECK-LABEL: @minnum_float_zeros_vec(
98 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float -0.000000e+00, float 0.000000e+00, float -0.000000e+00>
100 %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>)
104 define float @maxnum_float() {
105 ; CHECK-LABEL: @maxnum_float(
106 ; CHECK-NEXT: ret float 4.200000e+01
108 %1 = call float @llvm.maxnum.f32(float 5.0, float 42.0)
112 define bfloat @maxnum_bfloat() {
113 ; CHECK-LABEL: @maxnum_bfloat(
114 ; CHECK-NEXT: ret bfloat 0xR4228
116 %1 = call bfloat @llvm.maxnum.bf16(bfloat 5.0, bfloat 42.0)
120 define half @maxnum_half() {
121 ; CHECK-LABEL: @maxnum_half(
122 ; CHECK-NEXT: ret half 0xH5140
124 %1 = call half @llvm.maxnum.f16(half 5.0, half 42.0)
128 ; Check that maxnum constant folds to propagate non-NaN or greater argument
130 define <4 x float> @maxnum_float_vec() {
131 ; CHECK-LABEL: @maxnum_float_vec(
132 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 5.000000e+00, float 4.200000e+01, float 4.200000e+01>
134 %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.>)
138 define <4 x bfloat> @maxnum_bfloat_vec() {
139 ; CHECK-LABEL: @maxnum_bfloat_vec(
140 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR40A0, bfloat 0xR4228, bfloat 0xR4228>
142 %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.>)
146 define <4 x half> @maxnum_half_vec() {
147 ; CHECK-LABEL: @maxnum_half_vec(
148 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH4500, half 0xH5140, half 0xH5140>
150 %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.>)
154 ; Check that maxnum constant folds to propagate one of its argument zeros
156 define <4 x float> @maxnum_float_zeros_vec() {
157 ; CHECK-LABEL: @maxnum_float_zeros_vec(
158 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float -0.000000e+00, float 0.000000e+00, float -0.000000e+00>
160 %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>)
164 define float @minimum_float() {
165 ; CHECK-LABEL: @minimum_float(
166 ; CHECK-NEXT: ret float 5.000000e+00
168 %1 = call float @llvm.minimum.f32(float 5.0, float 42.0)
172 define bfloat @minimum_bfloat() {
173 ; CHECK-LABEL: @minimum_bfloat(
174 ; CHECK-NEXT: ret bfloat 0xR40A0
176 %1 = call bfloat @llvm.minimum.bf16(bfloat 5.0, bfloat 42.0)
180 define half @minimum_half() {
181 ; CHECK-LABEL: @minimum_half(
182 ; CHECK-NEXT: ret half 0xH4500
184 %1 = call half @llvm.minimum.f16(half 5.0, half 42.0)
188 ; Check that minimum propagates its NaN or smaller argument
190 define <4 x float> @minimum_float_vec() {
191 ; CHECK-LABEL: @minimum_float_vec(
192 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 0x7FF8000000000000, float 5.000000e+00>
194 %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.>)
198 define <4 x bfloat> @minimum_bfloat_vec() {
199 ; CHECK-LABEL: @minimum_bfloat_vec(
200 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR40A0>
202 %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.>)
206 define <4 x half> @minimum_half_vec() {
207 ; CHECK-LABEL: @minimum_half_vec(
208 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH7E00, half 0xH7E00, half 0xH4500>
210 %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.>)
214 ; Check that minimum treats -0.0 as smaller than 0.0 while constant folding
216 define <4 x float> @minimum_float_zeros_vec() {
217 ; CHECK-LABEL: @minimum_float_zeros_vec(
218 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>
220 %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>)
224 define float @maximum_float() {
225 ; CHECK-LABEL: @maximum_float(
226 ; CHECK-NEXT: ret float 4.200000e+01
228 %1 = call float @llvm.maximum.f32(float 5.0, float 42.0)
232 define bfloat @maximum_bfloat() {
233 ; CHECK-LABEL: @maximum_bfloat(
234 ; CHECK-NEXT: ret bfloat 0xR4228
236 %1 = call bfloat @llvm.maximum.bf16(bfloat 5.0, bfloat 42.0)
240 define half @maximum_half() {
241 ; CHECK-LABEL: @maximum_half(
242 ; CHECK-NEXT: ret half 0xH5140
244 %1 = call half @llvm.maximum.f16(half 5.0, half 42.0)
248 ; Check that maximum propagates its NaN or greater argument
250 define <4 x float> @maximum_float_vec() {
251 ; CHECK-LABEL: @maximum_float_vec(
252 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 0x7FF8000000000000, float 4.200000e+01>
254 %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.>)
258 define <4 x bfloat> @maximum_bfloat_vec() {
259 ; CHECK-LABEL: @maximum_bfloat_vec(
260 ; CHECK-NEXT: ret <4 x bfloat> <bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR7FC0, bfloat 0xR4228>
262 %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.>)
266 define <4 x half> @maximum_half_vec() {
267 ; CHECK-LABEL: @maximum_half_vec(
268 ; CHECK-NEXT: ret <4 x half> <half 0xH7E00, half 0xH7E00, half 0xH7E00, half 0xH5140>
270 %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.>)
274 ; Check that maximum treats -0.0 as smaller than 0.0 while constant folding
276 define <4 x float> @maximum_float_zeros_vec() {
277 ; CHECK-LABEL: @maximum_float_zeros_vec(
278 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00, float 0.000000e+00, float -0.000000e+00>
280 %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>)
285 ; CHECK-LABEL: @smax(
286 ; CHECK-NEXT: ret i8 -127
288 %r = call i8 @llvm.smax.i8(i8 128, i8 129)
292 define <5 x i8> @smax_vec() {
293 ; CHECK-LABEL: @smax_vec(
294 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 127, i8 poison, i8 42, i8 127>
296 %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>)
301 ; CHECK-LABEL: @smin(
302 ; CHECK-NEXT: ret i8 -128
304 %r = call i8 @llvm.smin.i8(i8 128, i8 127)
308 define <5 x i8> @smin_vec() {
309 ; CHECK-LABEL: @smin_vec(
310 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 -128, i8 poison, i8 42, i8 -127>
312 %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>)
317 ; CHECK-LABEL: @umax(
318 ; CHECK-NEXT: ret i8 -128
320 %r = call i8 @llvm.umax.i8(i8 128, i8 127)
324 define <5 x i8> @umax_vec() {
325 ; CHECK-LABEL: @umax_vec(
326 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 -1, i8 poison, i8 42, i8 -128>
328 %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>)
333 ; CHECK-LABEL: @umin(
334 ; CHECK-NEXT: ret i8 127
336 %r = call i8 @llvm.umin.i8(i8 128, i8 127)
340 define <5 x i8> @umin_vec() {
341 ; CHECK-LABEL: @umin_vec(
342 ; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 0, i8 poison, i8 42, i8 42>
344 %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>)