OSDN Git Service

[InstCombine] add tests for FP min/max with negated operands; NFC
authorSanjay Patel <spatel@rotateright.com>
Tue, 7 May 2019 16:25:43 +0000 (16:25 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 7 May 2019 16:25:43 +0000 (16:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360170 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/InstCombine/minmax-fp.ll

index 1141815..9cdbf4f 100644 (file)
@@ -255,3 +255,62 @@ define double @t17(i32 %x) {
   ret double %sel
 }
 
+define float @fneg_fmax(float %x, float %y) {
+; CHECK-LABEL: @fneg_fmax(
+; CHECK-NEXT:    [[N1:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT:    [[N2:%.*]] = fneg float [[Y:%.*]]
+; CHECK-NEXT:    [[COND:%.*]] = fcmp nnan ogt float [[N1]], [[N2]]
+; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[COND]], float [[N1]], float [[N2]]
+; CHECK-NEXT:    ret float [[MAX]]
+;
+  %n1 = fneg float %x
+  %n2 = fneg float %y
+  %cond = fcmp nnan ogt float %n1, %n2
+  %max = select i1 %cond, float %n1, float %n2
+  ret float %max
+}
+
+define <2 x float> @fsub_fmax(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fsub_fmax(
+; CHECK-NEXT:    [[N1:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
+; CHECK-NEXT:    [[N2:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[Y:%.*]]
+; CHECK-NEXT:    [[COND_INV:%.*]] = fcmp nnan nsz olt <2 x float> [[N1]], [[N2]]
+; CHECK-NEXT:    [[MAX:%.*]] = select <2 x i1> [[COND_INV]], <2 x float> [[N2]], <2 x float> [[N1]]
+; CHECK-NEXT:    ret <2 x float> [[MAX]]
+;
+  %n1 = fsub <2 x float> <float -0.0, float -0.0>, %x
+  %n2 = fsub <2 x float> <float -0.0, float -0.0>, %y
+  %cond = fcmp nsz nnan uge <2 x float> %n1, %n2
+  %max = select <2 x i1> %cond, <2 x float> %n1, <2 x float> %n2
+  ret <2 x float> %max
+}
+
+define <2 x double> @fsub_fmin(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: @fsub_fmin(
+; CHECK-NEXT:    [[N1:%.*]] = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[X:%.*]]
+; CHECK-NEXT:    [[N2:%.*]] = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[Y:%.*]]
+; CHECK-NEXT:    [[COND:%.*]] = fcmp nnan olt <2 x double> [[N1]], [[N2]]
+; CHECK-NEXT:    [[MAX:%.*]] = select <2 x i1> [[COND]], <2 x double> [[N1]], <2 x double> [[N2]]
+; CHECK-NEXT:    ret <2 x double> [[MAX]]
+;
+  %n1 = fsub <2 x double> <double -0.0, double -0.0>, %x
+  %n2 = fsub <2 x double> <double -0.0, double -0.0>, %y
+  %cond = fcmp nnan olt <2 x double> %n1, %n2
+  %max = select <2 x i1> %cond, <2 x double> %n1, <2 x double> %n2
+  ret <2 x double> %max
+}
+
+define double @fneg_fmin(double %x, double %y) {
+; CHECK-LABEL: @fneg_fmin(
+; CHECK-NEXT:    [[N1:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:    [[N2:%.*]] = fneg double [[Y:%.*]]
+; CHECK-NEXT:    [[COND_INV:%.*]] = fcmp nnan nsz ogt double [[N1]], [[N2]]
+; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[COND_INV]], double [[N2]], double [[N1]]
+; CHECK-NEXT:    ret double [[MAX]]
+;
+  %n1 = fneg double %x
+  %n2 = fneg double %y
+  %cond = fcmp nsz nnan ule double %n1, %n2
+  %max = select i1 %cond, double %n1, double %n2
+  ret double %max
+}