1 ; RUN: opt -S -instcombine < %s | FileCheck %s 2 3 declare float @llvm.minnum.f32(float, float) #0 4 declare float @llvm.minnum.v2f32(<2 x float>, <2 x float>) #0 5 declare <4 x float> @llvm.minnum.v4f32(<4 x float>, <4 x float>) #0 6 7 declare double @llvm.minnum.f64(double, double) #0 8 declare <2 x double> @llvm.minnum.v2f64(<2 x double>, <2 x double>) #0 9 10 declare float @llvm.maxnum.f32(float, float) #0 11 12 ; CHECK-LABEL: @constant_fold_minnum_f32 13 ; CHECK-NEXT: ret float 1.000000e+00 14 define float @constant_fold_minnum_f32() #0 { 15 %x = call float @llvm.minnum.f32(float 1.0, float 2.0) #0 16 ret float %x 17 } 18 19 ; CHECK-LABEL: @constant_fold_minnum_f32_inv 20 ; CHECK-NEXT: ret float 1.000000e+00 21 define float @constant_fold_minnum_f32_inv() #0 { 22 %x = call float @llvm.minnum.f32(float 2.0, float 1.0) #0 23 ret float %x 24 } 25 26 ; CHECK-LABEL: @constant_fold_minnum_f32_nan0 27 ; CHECK-NEXT: ret float 2.000000e+00 28 define float @constant_fold_minnum_f32_nan0() #0 { 29 %x = call float @llvm.minnum.f32(float 0x7FF8000000000000, float 2.0) #0 30 ret float %x 31 } 32 33 ; CHECK-LABEL: @constant_fold_minnum_f32_nan1 34 ; CHECK-NEXT: ret float 2.000000e+00 35 define float @constant_fold_minnum_f32_nan1() #0 { 36 %x = call float @llvm.minnum.f32(float 2.0, float 0x7FF8000000000000) #0 37 ret float %x 38 } 39 40 ; CHECK-LABEL: @constant_fold_minnum_f32_nan_nan 41 ; CHECK-NEXT: ret float 0x7FF8000000000000 42 define float @constant_fold_minnum_f32_nan_nan() #0 { 43 %x = call float @llvm.minnum.f32(float 0x7FF8000000000000, float 0x7FF8000000000000) #0 44 ret float %x 45 } 46 47 ; CHECK-LABEL: @constant_fold_minnum_f32_p0_p0 48 ; CHECK-NEXT: ret float 0.000000e+00 49 define float @constant_fold_minnum_f32_p0_p0() #0 { 50 %x = call float @llvm.minnum.f32(float 0.0, float 0.0) #0 51 ret float %x 52 } 53 54 ; CHECK-LABEL: @constant_fold_minnum_f32_p0_n0 55 ; CHECK-NEXT: ret float 0.000000e+00 56 define float @constant_fold_minnum_f32_p0_n0() #0 { 57 %x = call float @llvm.minnum.f32(float 0.0, float -0.0) #0 58 ret float %x 59 } 60 61 ; CHECK-LABEL: @constant_fold_minnum_f32_n0_p0 62 ; CHECK-NEXT: ret float -0.000000e+00 63 define float @constant_fold_minnum_f32_n0_p0() #0 { 64 %x = call float @llvm.minnum.f32(float -0.0, float 0.0) #0 65 ret float %x 66 } 67 68 ; CHECK-LABEL: @constant_fold_minnum_f32_n0_n0 69 ; CHECK-NEXT: ret float -0.000000e+00 70 define float @constant_fold_minnum_f32_n0_n0() #0 { 71 %x = call float @llvm.minnum.f32(float -0.0, float -0.0) #0 72 ret float %x 73 } 74 75 ; CHECK-LABEL: @constant_fold_minnum_v4f32 76 ; CHECK-NEXT: ret <4 x float> <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 5.000000e+00> 77 define <4 x float> @constant_fold_minnum_v4f32() #0 { 78 %x = call <4 x float> @llvm.minnum.v4f32(<4 x float> <float 1.0, float 8.0, float 3.0, float 9.0>, <4 x float> <float 2.0, float 2.0, float 10.0, float 5.0>) 79 ret <4 x float> %x 80 } 81 82 ; CHECK-LABEL: @constant_fold_minnum_f64 83 ; CHECK-NEXT: ret double 1.000000e+00 84 define double @constant_fold_minnum_f64() #0 { 85 %x = call double @llvm.minnum.f64(double 1.0, double 2.0) #0 86 ret double %x 87 } 88 89 ; CHECK-LABEL: @constant_fold_minnum_f64_nan0 90 ; CHECK-NEXT: ret double 2.000000e+00 91 define double @constant_fold_minnum_f64_nan0() #0 { 92 %x = call double @llvm.minnum.f64(double 0x7FF8000000000000, double 2.0) #0 93 ret double %x 94 } 95 96 ; CHECK-LABEL: @constant_fold_minnum_f64_nan1 97 ; CHECK-NEXT: ret double 2.000000e+00 98 define double @constant_fold_minnum_f64_nan1() #0 { 99 %x = call double @llvm.minnum.f64(double 2.0, double 0x7FF8000000000000) #0 100 ret double %x 101 } 102 103 ; CHECK-LABEL: @constant_fold_minnum_f64_nan_nan 104 ; CHECK-NEXT: ret double 0x7FF8000000000000 105 define double @constant_fold_minnum_f64_nan_nan() #0 { 106 %x = call double @llvm.minnum.f64(double 0x7FF8000000000000, double 0x7FF8000000000000) #0 107 ret double %x 108 } 109 110 ; CHECK-LABEL: @canonicalize_constant_minnum_f32 111 ; CHECK: call float @llvm.minnum.f32(float %x, float 1.000000e+00) 112 define float @canonicalize_constant_minnum_f32(float %x) #0 { 113 %y = call float @llvm.minnum.f32(float 1.0, float %x) #0 114 ret float %y 115 } 116 117 ; CHECK-LABEL: @noop_minnum_f32 118 ; CHECK-NEXT: ret float %x 119 define float @noop_minnum_f32(float %x) #0 { 120 %y = call float @llvm.minnum.f32(float %x, float %x) #0 121 ret float %y 122 } 123 124 ; CHECK-LABEL: @minnum_f32_nan_val 125 ; CHECK-NEXT: ret float %x 126 define float @minnum_f32_nan_val(float %x) #0 { 127 %y = call float @llvm.minnum.f32(float 0x7FF8000000000000, float %x) #0 128 ret float %y 129 } 130 131 ; CHECK-LABEL: @minnum_f32_val_nan 132 ; CHECK-NEXT: ret float %x 133 define float @minnum_f32_val_nan(float %x) #0 { 134 %y = call float @llvm.minnum.f32(float %x, float 0x7FF8000000000000) #0 135 ret float %y 136 } 137 138 ; CHECK-LABEL: @fold_minnum_f32_undef_undef 139 ; CHECK-NEXT: ret float undef 140 define float @fold_minnum_f32_undef_undef(float %x) nounwind { 141 %val = call float @llvm.minnum.f32(float undef, float undef) #0 142 ret float %val 143 } 144 145 ; CHECK-LABEL: @fold_minnum_f32_val_undef 146 ; CHECK-NEXT: ret float %x 147 define float @fold_minnum_f32_val_undef(float %x) nounwind { 148 %val = call float @llvm.minnum.f32(float %x, float undef) #0 149 ret float %val 150 } 151 152 ; CHECK-LABEL: @fold_minnum_f32_undef_val 153 ; CHECK-NEXT: ret float %x 154 define float @fold_minnum_f32_undef_val(float %x) nounwind { 155 %val = call float @llvm.minnum.f32(float undef, float %x) #0 156 ret float %val 157 } 158 159 ; CHECK-LABEL: @minnum_x_minnum_x_y 160 ; CHECK-NEXT: call float @llvm.minnum.f32(float %x, float %y) 161 ; CHECK-NEXT: ret float 162 define float @minnum_x_minnum_x_y(float %x, float %y) #0 { 163 %a = call float @llvm.minnum.f32(float %x, float %y) #0 164 %b = call float @llvm.minnum.f32(float %x, float %a) #0 165 ret float %b 166 } 167 168 ; CHECK-LABEL: @minnum_y_minnum_x_y 169 ; CHECK-NEXT: call float @llvm.minnum.f32(float %x, float %y) 170 ; CHECK-NEXT: ret float 171 define float @minnum_y_minnum_x_y(float %x, float %y) #0 { 172 %a = call float @llvm.minnum.f32(float %x, float %y) #0 173 %b = call float @llvm.minnum.f32(float %y, float %a) #0 174 ret float %b 175 } 176 177 ; CHECK-LABEL: @minnum_z_minnum_x_y 178 ; CHECK-NEXT: call float @llvm.minnum.f32(float %x, float %y) 179 ; CHECK-NEXT: call float @llvm.minnum.f32(float %z, float %a) 180 ; CHECK-NEXT: ret float 181 define float @minnum_z_minnum_x_y(float %x, float %y, float %z) #0 { 182 %a = call float @llvm.minnum.f32(float %x, float %y) #0 183 %b = call float @llvm.minnum.f32(float %z, float %a) #0 184 ret float %b 185 } 186 187 ; CHECK-LABEL: @minnum_minnum_x_y_z 188 ; CHECK-NEXT: call float @llvm.minnum.f32(float %x, float %y) 189 ; CHECK-NEXT: call float @llvm.minnum.f32(float %a, float %z) 190 ; CHECK-NEXT: ret float 191 define float @minnum_minnum_x_y_z(float %x, float %y, float %z) #0 { 192 %a = call float @llvm.minnum.f32(float %x, float %y) #0 193 %b = call float @llvm.minnum.f32(float %a, float %z) #0 194 ret float %b 195 } 196 197 ; CHECK-LABEL: @minnum4 198 ; CHECK-NEXT: call float @llvm.minnum.f32(float %x, float %y) 199 ; CHECK-NEXT: call float @llvm.minnum.f32(float %z, float %w) 200 ; CHECK-NEXT: call float @llvm.minnum.f32(float %a, float %b) 201 ; CHECK-NEXT: ret float 202 define float @minnum4(float %x, float %y, float %z, float %w) #0 { 203 %a = call float @llvm.minnum.f32(float %x, float %y) #0 204 %b = call float @llvm.minnum.f32(float %z, float %w) #0 205 %c = call float @llvm.minnum.f32(float %a, float %b) #0 206 ret float %c 207 } 208 209 ; CHECK-LABEL: @minnum_x_maxnum_x_y 210 ; CHECK-NEXT: call float @llvm.maxnum.f32 211 ; CHECK-NEXT: call float @llvm.minnum.f32 212 ; CHECK-NEXT: ret float 213 define float @minnum_x_maxnum_x_y(float %x, float %y) #0 { 214 %a = call float @llvm.maxnum.f32(float %x, float %y) #0 215 %b = call float @llvm.minnum.f32(float %x, float %a) #0 216 ret float %b 217 } 218 219 ; CHECK-LABEL: @maxnum_x_minnum_x_y 220 ; CHECK-NEXT: call float @llvm.minnum.f32 221 ; CHECK-NEXT: call float @llvm.maxnum.f32 222 ; CHECK-NEXT: ret float 223 define float @maxnum_x_minnum_x_y(float %x, float %y) #0 { 224 %a = call float @llvm.minnum.f32(float %x, float %y) #0 225 %b = call float @llvm.maxnum.f32(float %x, float %a) #0 226 ret float %b 227 } 228 229 ; CHECK-LABEL: @fold_minnum_f32_inf_val 230 ; CHECK-NEXT: call float @llvm.minnum.f32(float %x, float 0x7FF0000000000000) 231 ; CHECK-NEXT: ret float 232 define float @fold_minnum_f32_inf_val(float %x) nounwind { 233 %val = call float @llvm.minnum.f32(float 0x7FF0000000000000, float %x) #0 234 ret float %val 235 } 236 237 ; CHECK-LABEL: @fold_minnum_f32_minf_val 238 ; CHECK-NEXT: ret float 0xFFF0000000000000 239 define float @fold_minnum_f32_minf_val(float %x) nounwind { 240 %val = call float @llvm.minnum.f32(float 0xFFF0000000000000, float %x) #0 241 ret float %val 242 } 243 244 attributes #0 = { nounwind readnone } 245