1 ; RUN: opt -instcombine -S -o - %s | FileCheck %s
2 ; Tests that constant folding of min and max operations works as expected.
4 declare float @llvm.minnum.f32(float, float)
5 declare float @llvm.maxnum.f32(float, float)
6 declare <4 x float> @llvm.minnum.v4f32(<4 x float>, <4 x float>)
7 declare <4 x float> @llvm.maxnum.v4f32(<4 x float>, <4 x float>)
9 declare float @llvm.minimum.f32(float, float)
10 declare float @llvm.maximum.f32(float, float)
11 declare <4 x float> @llvm.minimum.v4f32(<4 x float>, <4 x float>)
12 declare <4 x float> @llvm.maximum.v4f32(<4 x float>, <4 x float>)
14 ; CHECK: define float @minnum_float() {
15 define float @minnum_float() {
16 ; CHECK-NEXT: ret float 5.000000e+00
17 %1 = call float @llvm.minnum.f32(float 5.0, float 42.0)
21 ; Check that minnum constant folds to propagate non-NaN or smaller argument
22 ; CHECK: define <4 x float> @minnum_float_vec() {
23 define <4 x float> @minnum_float_vec() {
24 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 5.000000e+00,
25 ; CHECK-SAME: float 4.200000e+01, float 5.000000e+00>
26 %1 = call <4 x float> @llvm.minnum.v4f32(
27 <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>,
28 <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>
33 ; Check that minnum constant folds to propagate one of its argument zeros
34 ; CHECK: define <4 x float> @minnum_float_zeros_vec() {
35 define <4 x float> @minnum_float_zeros_vec() {
36 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float {{-?}}0.000000e+00,
37 ; CHECK-SAME: float {{-?}}0.000000e+00, float -0.000000e+00>
38 %1 = call <4 x float> @llvm.minnum.v4f32(
39 <4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>,
40 <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>
45 ; CHECK: define float @maxnum_float() {
46 define float @maxnum_float() {
47 ; CHECK-NEXT: ret float 4.200000e+01
48 %1 = call float @llvm.maxnum.f32(float 5.0, float 42.0)
52 ; Check that maxnum constant folds to propagate non-NaN or greater argument
53 ; CHECK: define <4 x float> @maxnum_float_vec() {
54 define <4 x float> @maxnum_float_vec() {
55 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 5.000000e+00,
56 ; CHECK-SAME: float 4.200000e+01, float 4.200000e+01>
57 %1 = call <4 x float> @llvm.maxnum.v4f32(
58 <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>,
59 <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>
64 ; Check that maxnum constant folds to propagate one of its argument zeros
65 ; CHECK: define <4 x float> @maxnum_float_zeros_vec() {
66 define <4 x float> @maxnum_float_zeros_vec() {
67 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float {{-?}}0.000000e+00,
68 ; CHECK-SAME: float {{-?}}0.000000e+00, float -0.000000e+00>
69 %1 = call <4 x float> @llvm.maxnum.v4f32(
70 <4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>,
71 <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>
76 ; CHECK: define float @minimum_float() {
77 define float @minimum_float() {
78 ; CHECK-NEXT: ret float 5.000000e+00
79 %1 = call float @llvm.minimum.f32(float 5.0, float 42.0)
83 ; Check that minimum propagates its NaN or smaller argument
84 ; CHECK: define <4 x float> @minimum_float_vec() {
85 define <4 x float> @minimum_float_vec() {
86 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000,
87 ; CHECK-SAME: float 0x7FF8000000000000, float 5.000000e+00>
88 %1 = call <4 x float> @llvm.minimum.v4f32(
89 <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>,
90 <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>
95 ; Check that minimum treats -0.0 as smaller than 0.0 while constant folding
96 ; CHECK: define <4 x float> @minimum_float_zeros_vec() {
97 define <4 x float> @minimum_float_zeros_vec() {
98 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float -0.000000e+00,
99 ; CHECK-SAME: float -0.000000e+00, float -0.000000e+00>
100 %1 = call <4 x float> @llvm.minimum.v4f32(
101 <4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>,
102 <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>
107 ; CHECK: define float @maximum_float() {
108 define float @maximum_float() {
109 ; CHECK-NEXT: ret float 4.200000e+01
110 %1 = call float @llvm.maximum.f32(float 5.0, float 42.0)
114 ; Check that maximum propagates its NaN or greater argument
115 ; CHECK: define <4 x float> @maximum_float_vec() {
116 define <4 x float> @maximum_float_vec() {
117 ; CHECK-NEXT: ret <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000,
118 ; CHECK-SAME: float 0x7FF8000000000000, float 4.200000e+01>
119 %1 = call <4 x float> @llvm.maximum.v4f32(
120 <4 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000, float 42., float 42.>,
121 <4 x float> <float 0x7FF8000000000000, float 5., float 0x7FF8000000000000, float 5.>
126 ; Check that maximum treats -0.0 as smaller than 0.0 while constant folding
127 ; CHECK: define <4 x float> @maximum_float_zeros_vec() {
128 define <4 x float> @maximum_float_zeros_vec() {
129 ; CHECK-NEXT: ret <4 x float> <float 0.000000e+00, float 0.000000e+00,
130 ; CHECK-SAME: float 0.000000e+00, float -0.000000e+00>
131 %1 = call <4 x float> @llvm.maximum.v4f32(
132 <4 x float> <float 0.0, float -0.0, float 0.0, float -0.0>,
133 <4 x float> <float 0.0, float 0.0, float -0.0, float -0.0>