1; RUN: opt -S -instcombine < %s | FileCheck %s 2 3declare float @llvm.maxnum.f32(float, float) #0 4declare float @llvm.maxnum.v2f32(<2 x float>, <2 x float>) #0 5declare <4 x float> @llvm.maxnum.v4f32(<4 x float>, <4 x float>) #0 6 7declare double @llvm.maxnum.f64(double, double) #0 8declare <2 x double> @llvm.maxnum.v2f64(<2 x double>, <2 x double>) #0 9 10; CHECK-LABEL: @constant_fold_maxnum_f32 11; CHECK-NEXT: ret float 2.000000e+00 12define float @constant_fold_maxnum_f32() #0 { 13 %x = call float @llvm.maxnum.f32(float 1.0, float 2.0) #0 14 ret float %x 15} 16 17; CHECK-LABEL: @constant_fold_maxnum_f32_inv 18; CHECK-NEXT: ret float 2.000000e+00 19define float @constant_fold_maxnum_f32_inv() #0 { 20 %x = call float @llvm.maxnum.f32(float 2.0, float 1.0) #0 21 ret float %x 22} 23 24; CHECK-LABEL: @constant_fold_maxnum_f32_nan0 25; CHECK-NEXT: ret float 2.000000e+00 26define float @constant_fold_maxnum_f32_nan0() #0 { 27 %x = call float @llvm.maxnum.f32(float 0x7FF8000000000000, float 2.0) #0 28 ret float %x 29} 30 31; CHECK-LABEL: @constant_fold_maxnum_f32_nan1 32; CHECK-NEXT: ret float 2.000000e+00 33define float @constant_fold_maxnum_f32_nan1() #0 { 34 %x = call float @llvm.maxnum.f32(float 2.0, float 0x7FF8000000000000) #0 35 ret float %x 36} 37 38; CHECK-LABEL: @constant_fold_maxnum_f32_nan_nan 39; CHECK-NEXT: ret float 0x7FF8000000000000 40define float @constant_fold_maxnum_f32_nan_nan() #0 { 41 %x = call float @llvm.maxnum.f32(float 0x7FF8000000000000, float 0x7FF8000000000000) #0 42 ret float %x 43} 44 45; CHECK-LABEL: @constant_fold_maxnum_f32_p0_p0 46; CHECK-NEXT: ret float 0.000000e+00 47define float @constant_fold_maxnum_f32_p0_p0() #0 { 48 %x = call float @llvm.maxnum.f32(float 0.0, float 0.0) #0 49 ret float %x 50} 51 52; CHECK-LABEL: @constant_fold_maxnum_f32_p0_n0 53; CHECK-NEXT: ret float 0.000000e+00 54define float @constant_fold_maxnum_f32_p0_n0() #0 { 55 %x = call float @llvm.maxnum.f32(float 0.0, float -0.0) #0 56 ret float %x 57} 58 59; CHECK-LABEL: @constant_fold_maxnum_f32_n0_p0 60; CHECK-NEXT: ret float -0.000000e+00 61define float @constant_fold_maxnum_f32_n0_p0() #0 { 62 %x = call float @llvm.maxnum.f32(float -0.0, float 0.0) #0 63 ret float %x 64} 65 66; CHECK-LABEL: @constant_fold_maxnum_f32_n0_n0 67; CHECK-NEXT: ret float -0.000000e+00 68define float @constant_fold_maxnum_f32_n0_n0() #0 { 69 %x = call float @llvm.maxnum.f32(float -0.0, float -0.0) #0 70 ret float %x 71} 72 73; CHECK-LABEL: @constant_fold_maxnum_v4f32 74; CHECK-NEXT: ret <4 x float> <float 2.000000e+00, float 8.000000e+00, float 1.000000e+01, float 9.000000e+00> 75define <4 x float> @constant_fold_maxnum_v4f32() #0 { 76 %x = call <4 x float> @llvm.maxnum.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>) 77 ret <4 x float> %x 78} 79 80; CHECK-LABEL: @constant_fold_maxnum_f64 81; CHECK-NEXT: ret double 2.000000e+00 82define double @constant_fold_maxnum_f64() #0 { 83 %x = call double @llvm.maxnum.f64(double 1.0, double 2.0) #0 84 ret double %x 85} 86 87; CHECK-LABEL: @constant_fold_maxnum_f64_nan0 88; CHECK-NEXT: ret double 2.000000e+00 89define double @constant_fold_maxnum_f64_nan0() #0 { 90 %x = call double @llvm.maxnum.f64(double 0x7FF8000000000000, double 2.0) #0 91 ret double %x 92} 93 94; CHECK-LABEL: @constant_fold_maxnum_f64_nan1 95; CHECK-NEXT: ret double 2.000000e+00 96define double @constant_fold_maxnum_f64_nan1() #0 { 97 %x = call double @llvm.maxnum.f64(double 2.0, double 0x7FF8000000000000) #0 98 ret double %x 99} 100 101; CHECK-LABEL: @constant_fold_maxnum_f64_nan_nan 102; CHECK-NEXT: ret double 0x7FF8000000000000 103define double @constant_fold_maxnum_f64_nan_nan() #0 { 104 %x = call double @llvm.maxnum.f64(double 0x7FF8000000000000, double 0x7FF8000000000000) #0 105 ret double %x 106} 107 108; CHECK-LABEL: @canonicalize_constant_maxnum_f32 109; CHECK: call float @llvm.maxnum.f32(float %x, float 1.000000e+00) 110define float @canonicalize_constant_maxnum_f32(float %x) #0 { 111 %y = call float @llvm.maxnum.f32(float 1.0, float %x) #0 112 ret float %y 113} 114 115; CHECK-LABEL: @noop_maxnum_f32 116; CHECK-NEXT: ret float %x 117define float @noop_maxnum_f32(float %x) #0 { 118 %y = call float @llvm.maxnum.f32(float %x, float %x) #0 119 ret float %y 120} 121 122; CHECK-LABEL: @maxnum_f32_nan_val 123; CHECK-NEXT: ret float %x 124define float @maxnum_f32_nan_val(float %x) #0 { 125 %y = call float @llvm.maxnum.f32(float 0x7FF8000000000000, float %x) #0 126 ret float %y 127} 128 129; CHECK-LABEL: @maxnum_f32_val_nan 130; CHECK-NEXT: ret float %x 131define float @maxnum_f32_val_nan(float %x) #0 { 132 %y = call float @llvm.maxnum.f32(float %x, float 0x7FF8000000000000) #0 133 ret float %y 134} 135 136; CHECK-LABEL: @fold_maxnum_f32_undef_undef 137; CHECK-NEXT: ret float undef 138define float @fold_maxnum_f32_undef_undef(float %x) nounwind { 139 %val = call float @llvm.maxnum.f32(float undef, float undef) #0 140 ret float %val 141} 142 143; CHECK-LABEL: @fold_maxnum_f32_val_undef 144; CHECK-NEXT: ret float %x 145define float @fold_maxnum_f32_val_undef(float %x) nounwind { 146 %val = call float @llvm.maxnum.f32(float %x, float undef) #0 147 ret float %val 148} 149 150; CHECK-LABEL: @fold_maxnum_f32_undef_val 151; CHECK-NEXT: ret float %x 152define float @fold_maxnum_f32_undef_val(float %x) nounwind { 153 %val = call float @llvm.maxnum.f32(float undef, float %x) #0 154 ret float %val 155} 156 157; CHECK-LABEL: @maxnum_x_maxnum_x_y 158; CHECK-NEXT: call float @llvm.maxnum.f32(float %x, float %y) 159; CHECK-NEXT: ret float 160define float @maxnum_x_maxnum_x_y(float %x, float %y) #0 { 161 %a = call float @llvm.maxnum.f32(float %x, float %y) #0 162 %b = call float @llvm.maxnum.f32(float %x, float %a) #0 163 ret float %b 164} 165 166; CHECK-LABEL: @maxnum_y_maxnum_x_y 167; CHECK-NEXT: call float @llvm.maxnum.f32(float %x, float %y) 168; CHECK-NEXT: ret float 169define float @maxnum_y_maxnum_x_y(float %x, float %y) #0 { 170 %a = call float @llvm.maxnum.f32(float %x, float %y) #0 171 %b = call float @llvm.maxnum.f32(float %y, float %a) #0 172 ret float %b 173} 174 175; CHECK-LABEL: @maxnum_z_maxnum_x_y 176; CHECK-NEXT: call float @llvm.maxnum.f32(float %x, float %y) 177; CHECK-NEXT: call float @llvm.maxnum.f32(float %z, float %a) 178; CHECK-NEXT: ret float 179define float @maxnum_z_maxnum_x_y(float %x, float %y, float %z) #0 { 180 %a = call float @llvm.maxnum.f32(float %x, float %y) #0 181 %b = call float @llvm.maxnum.f32(float %z, float %a) #0 182 ret float %b 183} 184 185; CHECK-LABEL: @maxnum_maxnum_x_y_z 186; CHECK-NEXT: call float @llvm.maxnum.f32(float %x, float %y) 187; CHECK-NEXT: call float @llvm.maxnum.f32(float %a, float %z) 188; CHECK-NEXT: ret float 189define float @maxnum_maxnum_x_y_z(float %x, float %y, float %z) #0 { 190 %a = call float @llvm.maxnum.f32(float %x, float %y) #0 191 %b = call float @llvm.maxnum.f32(float %a, float %z) #0 192 ret float %b 193} 194 195; CHECK-LABEL: @maxnum4 196; CHECK-NEXT: call float @llvm.maxnum.f32(float %x, float %y) 197; CHECK-NEXT: call float @llvm.maxnum.f32(float %z, float %w) 198; CHECK-NEXT: call float @llvm.maxnum.f32(float %a, float %b) 199; CHECK-NEXT: ret float 200define float @maxnum4(float %x, float %y, float %z, float %w) #0 { 201 %a = call float @llvm.maxnum.f32(float %x, float %y) #0 202 %b = call float @llvm.maxnum.f32(float %z, float %w) #0 203 %c = call float @llvm.maxnum.f32(float %a, float %b) #0 204 ret float %c 205} 206 207; CHECK-LABEL: @fold_maxnum_f32_inf_val 208; CHECK-NEXT: ret float 0x7FF0000000000000 209define float @fold_maxnum_f32_inf_val(float %x) nounwind { 210 %val = call float @llvm.maxnum.f32(float 0x7FF0000000000000, float %x) #0 211 ret float %val 212} 213 214; CHECK-LABEL: @fold_maxnum_f32_neginf_val 215; CHECK-NEXT: call float @llvm.maxnum.f32(float %x, float 0xFFF0000000000000) 216; CHECK-NEXT: ret float 217define float @fold_maxnum_f32_neginf_val(float %x) nounwind { 218 %val = call float @llvm.maxnum.f32(float 0xFFF0000000000000, float %x) #0 219 ret float %val 220} 221 222attributes #0 = { nounwind readnone } 223