[llvm] r332025 - [InstCombine] add minnum/maxnum tests (PR37404, PR37405); NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu May 10 12:21:08 PDT 2018
Author: spatel
Date: Thu May 10 12:21:08 2018
New Revision: 332025
URL: http://llvm.org/viewvc/llvm-project?rev=332025&view=rev
Log:
[InstCombine] add minnum/maxnum tests (PR37404, PR37405); NFC
Modified:
llvm/trunk/test/Transforms/InstCombine/maxnum.ll
llvm/trunk/test/Transforms/InstCombine/minnum.ll
Modified: llvm/trunk/test/Transforms/InstCombine/maxnum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/maxnum.ll?rev=332025&r1=332024&r2=332025&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/maxnum.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/maxnum.ll Thu May 10 12:21:08 2018
@@ -2,7 +2,7 @@
; RUN: opt -S -instcombine < %s | FileCheck %s
declare float @llvm.maxnum.f32(float, float)
-declare float @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
+declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
declare <4 x float> @llvm.maxnum.v4f32(<4 x float>, <4 x float>)
declare double @llvm.maxnum.f64(double, double)
@@ -249,3 +249,85 @@ define float @fold_maxnum_f32_neginf_val
ret float %val
}
+; PR37404 - https://bugs.llvm.org/show_bug.cgi?id=37404
+
+define <2 x float> @neg_neg(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @neg_neg(
+; CHECK-NEXT: [[NEGX:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call <2 x float> @llvm.maxnum.v2f32(<2 x float> [[NEGX]], <2 x float> [[NEGY]])
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %negx = fsub <2 x float> <float -0.0, float -0.0>, %x
+ %negy = fsub <2 x float> <float -0.0, float -0.0>, %y
+ %r = call <2 x float> @llvm.maxnum.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).
+; Also, make sure this works with vectors.
+
+define float @neg_neg_vec_fmf(float %x, float %y) {
+; CHECK-LABEL: @neg_neg_vec_fmf(
+; CHECK-NEXT: [[NEGX:%.*]] = fsub arcp float -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub afn float -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call fast float @llvm.maxnum.f32(float [[NEGX]], float [[NEGY]])
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fsub arcp float -0.0, %x
+ %negy = fsub afn float -0.0, %y
+ %r = call fast float @llvm.maxnum.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.
+
+declare void @use(float)
+define float @neg_neg_extra_use_x(float %x, float %y) {
+; CHECK-LABEL: @neg_neg_extra_use_x(
+; CHECK-NEXT: [[NEGX:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.maxnum.f32(float [[NEGX]], float [[NEGY]])
+; CHECK-NEXT: call void @use(float [[NEGX]])
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fsub float -0.0, %x
+ %negy = fsub float -0.0, %y
+ %r = call float @llvm.maxnum.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: [[NEGX:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.maxnum.f32(float [[NEGX]], float [[NEGY]])
+; CHECK-NEXT: call void @use(float [[NEGY]])
+; CHECK-NEXT: ret float [[R]]
+;
+ %negx = fsub float -0.0, %x
+ %negy = fsub float -0.0, %y
+ %r = call float @llvm.maxnum.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:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub float -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.maxnum.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 = fsub float -0.0, %x
+ %negy = fsub float -0.0, %y
+ %r = call float @llvm.maxnum.f32(float %negx, float %negy)
+ call void @use(float %negx)
+ call void @use(float %negy)
+ ret float %r
+}
+
Modified: llvm/trunk/test/Transforms/InstCombine/minnum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/minnum.ll?rev=332025&r1=332024&r2=332025&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/minnum.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/minnum.ll Thu May 10 12:21:08 2018
@@ -273,3 +273,85 @@ define float @fold_minnum_f32_minf_val(f
ret float %val
}
+; PR37405 - https://bugs.llvm.org/show_bug.cgi?id=37405
+
+define double @neg_neg(double %x, double %y) {
+; CHECK-LABEL: @neg_neg(
+; CHECK-NEXT: [[NEGX:%.*]] = fsub double -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub double -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call double @llvm.minnum.f64(double [[NEGX]], double [[NEGY]])
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fsub double -0.0, %x
+ %negy = fsub double -0.0, %y
+ %r = call double @llvm.minnum.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.
+
+define <2 x double> @neg_neg_vec_fmf(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: @neg_neg_vec_fmf(
+; CHECK-NEXT: [[NEGX:%.*]] = fsub reassoc <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub fast <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call nnan ninf <2 x double> @llvm.minnum.v2f64(<2 x double> [[NEGX]], <2 x double> [[NEGY]])
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %negx = fsub reassoc <2 x double> <double -0.0, double -0.0>, %x
+ %negy = fsub fast <2 x double> <double -0.0, double -0.0>, %y
+ %r = call nnan ninf <2 x double> @llvm.minnum.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.
+
+declare void @use(double)
+define double @neg_neg_extra_use_x(double %x, double %y) {
+; CHECK-LABEL: @neg_neg_extra_use_x(
+; CHECK-NEXT: [[NEGX:%.*]] = fsub double -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub double -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call double @llvm.minnum.f64(double [[NEGX]], double [[NEGY]])
+; CHECK-NEXT: call void @use(double [[NEGX]])
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fsub double -0.0, %x
+ %negy = fsub double -0.0, %y
+ %r = call double @llvm.minnum.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: [[NEGX:%.*]] = fsub double -0.000000e+00, [[X:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub double -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call double @llvm.minnum.f64(double [[NEGX]], double [[NEGY]])
+; CHECK-NEXT: call void @use(double [[NEGY]])
+; CHECK-NEXT: ret double [[R]]
+;
+ %negx = fsub double -0.0, %x
+ %negy = fsub double -0.0, %y
+ %r = call double @llvm.minnum.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:%.*]]
+; CHECK-NEXT: [[NEGY:%.*]] = fsub double -0.000000e+00, [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call double @llvm.minnum.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 = fsub double -0.0, %x
+ %negy = fsub double -0.0, %y
+ %r = call double @llvm.minnum.f64(double %negx, double %negy)
+ call void @use(double %negx)
+ call void @use(double %negy)
+ ret double %r
+}
+
More information about the llvm-commits
mailing list