[NFC][InstCombine] Add unary FNeg tests to maximum.ll/minimum.ll
authorCameron McInally <cameron.mcinally@nyu.edu>
Thu, 23 May 2019 14:53:42 +0000 (14:53 +0000)
committerCameron McInally <cameron.mcinally@nyu.edu>
Thu, 23 May 2019 14:53:42 +0000 (14:53 +0000)
llvm-svn: 361500

llvm/test/Transforms/InstCombine/maximum.ll
llvm/test/Transforms/InstCombine/minimum.ll

index bd97a37..d02cb99 100644 (file)
@@ -226,6 +226,18 @@ define <2 x float> @neg_neg(<2 x float> %x, <2 x float> %y) {
   ret <2 x float> %r
 }
 
+define <2 x float> @unary_neg_neg(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @unary_neg_neg(
+; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x float> @llvm.minimum.v2f32(<2 x float> [[X:%.*]], <2 x float> [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
+; CHECK-NEXT:    ret <2 x float> [[R]]
+;
+  %negx = fneg <2 x float> %x
+  %negy = fneg <2 x float> %y
+  %r = call <2 x float> @llvm.maximum.v2f32(<2 x float> %negx, <2 x float> %negy)
+  ret <2 x float> %r
+}
+
 ; FMF is not required, but it should be propagated from the intrinsic (not the fnegs).
 
 define float @neg_neg_vec_fmf(float %x, float %y) {
@@ -240,6 +252,18 @@ define float @neg_neg_vec_fmf(float %x, float %y) {
   ret float %r
 }
 
+define float @unary_neg_neg_vec_fmf(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_vec_fmf(
+; CHECK-NEXT:    [[TMP1:%.*]] = call fast float @llvm.minimum.f32(float [[X:%.*]], float [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fsub fast float -0.000000e+00, [[TMP1]]
+; CHECK-NEXT:    ret float [[R]]
+;
+  %negx = fneg arcp float %x
+  %negy = fneg afn float %y
+  %r = call fast float @llvm.maximum.f32(float %negx, float %negy)
+  ret float %r
+}
+
 ; 1 extra use of an intermediate value should still allow the fold,
 ; but 2 would require more instructions than we started with.
 
@@ -259,6 +283,21 @@ define float @neg_neg_extra_use_x(float %x, float %y) {
   ret float %r
 }
 
+define float @unary_neg_neg_extra_use_x(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x(
+; CHECK-NEXT:    [[NEGX:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call float @llvm.minimum.f32(float [[X]], float [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fsub float -0.000000e+00, [[TMP1]]
+; CHECK-NEXT:    call void @use(float [[NEGX]])
+; CHECK-NEXT:    ret float [[R]]
+;
+  %negx = fneg float %x
+  %negy = fneg float %y
+  %r = call float @llvm.maximum.f32(float %negx, float %negy)
+  call void @use(float %negx)
+  ret float %r
+}
+
 define float @neg_neg_extra_use_y(float %x, float %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_y(
 ; CHECK-NEXT:    [[NEGY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
@@ -274,6 +313,21 @@ define float @neg_neg_extra_use_y(float %x, float %y) {
   ret float %r
 }
 
+define float @unary_neg_neg_extra_use_y(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_y(
+; CHECK-NEXT:    [[NEGY:%.*]] = fneg float [[Y:%.*]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call float @llvm.minimum.f32(float [[X:%.*]], float [[Y]])
+; CHECK-NEXT:    [[R:%.*]] = fsub float -0.000000e+00, [[TMP1]]
+; CHECK-NEXT:    call void @use(float [[NEGY]])
+; CHECK-NEXT:    ret float [[R]]
+;
+  %negx = fneg float %x
+  %negy = fneg float %y
+  %r = call float @llvm.maximum.f32(float %negx, float %negy)
+  call void @use(float %negy)
+  ret float %r
+}
+
 define float @neg_neg_extra_use_x_and_y(float %x, float %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_x_and_y(
 ; CHECK-NEXT:    [[NEGX:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
@@ -290,3 +344,20 @@ define float @neg_neg_extra_use_x_and_y(float %x, float %y) {
   call void @use(float %negy)
   ret float %r
 }
+
+define float @unary_neg_neg_extra_use_x_and_y(float %x, float %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x_and_y(
+; CHECK-NEXT:    [[NEGX:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT:    [[NEGY:%.*]] = fneg float [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = call float @llvm.maximum.f32(float [[NEGX]], float [[NEGY]])
+; CHECK-NEXT:    call void @use(float [[NEGX]])
+; CHECK-NEXT:    call void @use(float [[NEGY]])
+; CHECK-NEXT:    ret float [[R]]
+;
+  %negx = fneg float %x
+  %negy = fneg float %y
+  %r = call float @llvm.maximum.f32(float %negx, float %negy)
+  call void @use(float %negx)
+  call void @use(float %negy)
+  ret float %r
+}
index 32aae64..9ef9cb7 100644 (file)
@@ -250,6 +250,18 @@ define double @neg_neg(double %x, double %y) {
   ret double %r
 }
 
+define double @unary_neg_neg(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg(
+; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.maximum.f64(double [[X:%.*]], double [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; CHECK-NEXT:    ret double [[R]]
+;
+  %negx = fneg double %x
+  %negy = fneg double %y
+  %r = call double @llvm.minimum.f64(double %negx, double %negy)
+  ret double %r
+}
+
 ; FMF is not required, but it should be propagated from the intrinsic (not the fnegs).
 ; Also, make sure this works with vectors.
 
@@ -265,6 +277,18 @@ define <2 x double> @neg_neg_vec_fmf(<2 x double> %x, <2 x double> %y) {
   ret <2 x double> %r
 }
 
+define <2 x double> @unary_neg_neg_vec_fmf(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: @unary_neg_neg_vec_fmf(
+; CHECK-NEXT:    [[TMP1:%.*]] = call nnan ninf <2 x double> @llvm.maximum.v2f64(<2 x double> [[X:%.*]], <2 x double> [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fsub nnan ninf <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[TMP1]]
+; CHECK-NEXT:    ret <2 x double> [[R]]
+;
+  %negx = fneg reassoc <2 x double> %x
+  %negy = fneg fast <2 x double> %y
+  %r = call nnan ninf <2 x double> @llvm.minimum.v2f64(<2 x double> %negx, <2 x double> %negy)
+  ret <2 x double> %r
+}
+
 ; 1 extra use of an intermediate value should still allow the fold,
 ; but 2 would require more instructions than we started with.
 
@@ -284,6 +308,21 @@ define double @neg_neg_extra_use_x(double %x, double %y) {
   ret double %r
 }
 
+define double @unary_neg_neg_extra_use_x(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x(
+; CHECK-NEXT:    [[NEGX:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.maximum.f64(double [[X]], double [[Y:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; CHECK-NEXT:    call void @use(double [[NEGX]])
+; CHECK-NEXT:    ret double [[R]]
+;
+  %negx = fneg double %x
+  %negy = fneg double %y
+  %r = call double @llvm.minimum.f64(double %negx, double %negy)
+  call void @use(double %negx)
+  ret double %r
+}
+
 define double @neg_neg_extra_use_y(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_y(
 ; CHECK-NEXT:    [[NEGY:%.*]] = fsub double -0.000000e+00, [[Y:%.*]]
@@ -299,6 +338,21 @@ define double @neg_neg_extra_use_y(double %x, double %y) {
   ret double %r
 }
 
+define double @unary_neg_neg_extra_use_y(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_y(
+; CHECK-NEXT:    [[NEGY:%.*]] = fneg double [[Y:%.*]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call double @llvm.maximum.f64(double [[X:%.*]], double [[Y]])
+; CHECK-NEXT:    [[R:%.*]] = fsub double -0.000000e+00, [[TMP1]]
+; CHECK-NEXT:    call void @use(double [[NEGY]])
+; CHECK-NEXT:    ret double [[R]]
+;
+  %negx = fneg double %x
+  %negy = fneg double %y
+  %r = call double @llvm.minimum.f64(double %negx, double %negy)
+  call void @use(double %negy)
+  ret double %r
+}
+
 define double @neg_neg_extra_use_x_and_y(double %x, double %y) {
 ; CHECK-LABEL: @neg_neg_extra_use_x_and_y(
 ; CHECK-NEXT:    [[NEGX:%.*]] = fsub double -0.000000e+00, [[X:%.*]]
@@ -315,3 +369,20 @@ define double @neg_neg_extra_use_x_and_y(double %x, double %y) {
   call void @use(double %negy)
   ret double %r
 }
+
+define double @unary_neg_neg_extra_use_x_and_y(double %x, double %y) {
+; CHECK-LABEL: @unary_neg_neg_extra_use_x_and_y(
+; CHECK-NEXT:    [[NEGX:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT:    [[NEGY:%.*]] = fneg double [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = call double @llvm.minimum.f64(double [[NEGX]], double [[NEGY]])
+; CHECK-NEXT:    call void @use(double [[NEGX]])
+; CHECK-NEXT:    call void @use(double [[NEGY]])
+; CHECK-NEXT:    ret double [[R]]
+;
+  %negx = fneg double %x
+  %negy = fneg double %y
+  %r = call double @llvm.minimum.f64(double %negx, double %negy)
+  call void @use(double %negx)
+  call void @use(double %negy)
+  ret double %r
+}