[llvm] r373788 - [InstCombine] add tests for fneg disguised as fmul; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 13:54:15 PDT 2019
Author: spatel
Date: Fri Oct 4 13:54:14 2019
New Revision: 373788
URL: http://llvm.org/viewvc/llvm-project?rev=373788&view=rev
Log:
[InstCombine] add tests for fneg disguised as fmul; NFC
Modified:
llvm/trunk/test/Transforms/InstCombine/fmul.ll
Modified: llvm/trunk/test/Transforms/InstCombine/fmul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul.ll?rev=373788&r1=373787&r2=373788&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul.ll Fri Oct 4 13:54:14 2019
@@ -991,3 +991,77 @@ define double @fmul_negated_constant_exp
%r = fmul double %x, fsub (double -0.000000e+00, double bitcast (i64 ptrtoint (i8** getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* @g, i64 0, inrange i32 0, i64 2) to i64) to double))
ret double %r
}
+
+define float @negate_if_true(float %x, i1 %cond) {
+; CHECK-LABEL: @negate_if_true(
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float -1.000000e+00, float 1.000000e+00
+; CHECK-NEXT: [[R:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %sel = select i1 %cond, float -1.0, float 1.0
+ %r = fmul float %sel, %x
+ ret float %r
+}
+
+define float @negate_if_false(float %x, i1 %cond) {
+; CHECK-LABEL: @negate_if_false(
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float 1.000000e+00, float -1.000000e+00
+; CHECK-NEXT: [[R:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %sel = select i1 %cond, float 1.0, float -1.0
+ %r = fmul float %sel, %x
+ ret float %r
+}
+
+define <2 x double> @negate_if_true_commute(<2 x double> %px, i1 %cond) {
+; CHECK-LABEL: @negate_if_true_commute(
+; CHECK-NEXT: [[X:%.*]] = fdiv <2 x double> <double 4.200000e+01, double 4.200000e+01>, [[PX:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x double> <double -1.000000e+00, double -1.000000e+00>, <2 x double> <double 1.000000e+00, double 1.000000e+00>
+; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %x = fdiv <2 x double> <double 42.0, double 42.0>, %px ; thwart complexity-based canonicalization
+ %sel = select i1 %cond, <2 x double> <double -1.0, double -1.0>, <2 x double> <double 1.0, double 1.0>
+ %r = fmul <2 x double> %x, %sel
+ ret <2 x double> %r
+}
+
+define <2 x double> @negate_if_false_commute(<2 x double> %px, <2 x i1> %cond) {
+; CHECK-LABEL: @negate_if_false_commute(
+; CHECK-NEXT: [[X:%.*]] = fdiv <2 x double> <double 4.200000e+01, double 5.100000e+00>, [[PX:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[COND:%.*]], <2 x double> <double 1.000000e+00, double 1.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>
+; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %x = fdiv <2 x double> <double 42.0, double 5.1>, %px ; thwart complexity-based canonicalization
+ %sel = select <2 x i1> %cond, <2 x double> <double 1.0, double 1.0>, <2 x double> <double -1.0, double -1.0>
+ %r = fmul <2 x double> %x, %sel
+ ret <2 x double> %r
+}
+
+define float @negate_if_true_extra_use(float %x, i1 %cond) {
+; CHECK-LABEL: @negate_if_true_extra_use(
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], float -1.000000e+00, float 1.000000e+00
+; CHECK-NEXT: call void @use_f32(float [[SEL]])
+; CHECK-NEXT: [[R:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %sel = select i1 %cond, float -1.0, float 1.0
+ call void @use_f32(float %sel)
+ %r = fmul float %sel, %x
+ ret float %r
+}
+
+define <2 x double> @negate_if_true_wrong_constant(<2 x double> %px, i1 %cond) {
+; CHECK-LABEL: @negate_if_true_wrong_constant(
+; CHECK-NEXT: [[X:%.*]] = fdiv <2 x double> <double 4.200000e+01, double 4.200000e+01>, [[PX:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x double> <double -1.000000e+00, double 0.000000e+00>, <2 x double> <double 1.000000e+00, double 1.000000e+00>
+; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]]
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %x = fdiv <2 x double> <double 42.0, double 42.0>, %px ; thwart complexity-based canonicalization
+ %sel = select i1 %cond, <2 x double> <double -1.0, double 0.0>, <2 x double> <double 1.0, double 1.0>
+ %r = fmul <2 x double> %x, %sel
+ ret <2 x double> %r
+}
More information about the llvm-commits
mailing list