]> granicus.if.org Git - llvm/commitdiff
Pre-commit test cases for D64713.
authorJay Foad <jay.foad@gmail.com>
Mon, 21 Oct 2019 15:01:59 +0000 (15:01 +0000)
committerJay Foad <jay.foad@gmail.com>
Mon, 21 Oct 2019 15:01:59 +0000 (15:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375418 91177308-0d34-0410-b5e6-96231b3b80d8

test/Transforms/InstCombine/fmul.ll
test/Transforms/InstCombine/mul.ll

index d53062aa5776060d707fda4d8e8504a35f6c1021..adc9381631a63ac1d640145bcbc7d21a34ad99fb 100644 (file)
@@ -1069,3 +1069,53 @@ define <2 x double> @negate_if_true_wrong_constant(<2 x double> %px, i1 %cond) {
   %r = fmul <2 x double> %x, %sel
   ret <2 x double> %r
 }
+
+; X *fast (C ? 1.0 : 0.0) -> C ? X : 0.0
+define float @fmul_select(float %x, i1 %c) {
+; CHECK-LABEL: @fmul_select(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], float 1.000000e+00, float 0.000000e+00
+; CHECK-NEXT:    [[MUL:%.*]] = fmul fast float [[SEL]], [[X:%.*]]
+; CHECK-NEXT:    ret float [[MUL]]
+;
+  %sel = select i1 %c, float 1.0, float 0.0
+  %mul = fmul fast float %sel, %x
+  ret float %mul
+}
+
+; X *fast (C ? 1.0 : 0.0) -> C ? X : 0.0
+define <2 x float> @fmul_select_vec(<2 x float> %x, i1 %c) {
+; CHECK-LABEL: @fmul_select_vec(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> zeroinitializer
+; CHECK-NEXT:    [[MUL:%.*]] = fmul fast <2 x float> [[SEL]], [[X:%.*]]
+; CHECK-NEXT:    ret <2 x float> [[MUL]]
+;
+  %sel = select i1 %c, <2 x float> <float 1.0, float 1.0>, <2 x float> zeroinitializer
+  %mul = fmul fast <2 x float> %sel, %x
+  ret <2 x float> %mul
+}
+
+; Without fast math flags we can't optimize X * (C ? 1.0 : 0.0) -> C ? X : 0.0
+define float @fmul_select_strict(float %x, i1 %c) {
+; CHECK-LABEL: @fmul_select_strict(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], float 1.000000e+00, float 0.000000e+00
+; CHECK-NEXT:    [[MUL:%.*]] = fmul float [[SEL]], [[X:%.*]]
+; CHECK-NEXT:    ret float [[MUL]]
+;
+  %sel = select i1 %c, float 1.0, float 0.0
+  %mul = fmul float %sel, %x
+  ret float %mul
+}
+
+; sqrt(X) *fast (C ? sqrt(X) : 1.0) -> C ? X : sqrt(X)
+define double @fmul_sqrt_select(double %x, i1 %c) {
+; CHECK-LABEL: @fmul_sqrt_select(
+; CHECK-NEXT:    [[SQR:%.*]] = call double @llvm.sqrt.f64(double [[X:%.*]])
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], double [[SQR]], double 1.000000e+00
+; CHECK-NEXT:    [[MUL:%.*]] = fmul fast double [[SQR]], [[SEL]]
+; CHECK-NEXT:    ret double [[MUL]]
+;
+  %sqr = call double @llvm.sqrt.f64(double %x)
+  %sel = select i1 %c, double %sqr, double 1.0
+  %mul = fmul fast double %sqr, %sel
+  ret double %mul
+}
index f106026762babce8feedd0e2bdd6dad339cdb0ec..5064bbae71d8d6ca80d6fcfd99c4ed139741a807 100644 (file)
@@ -595,3 +595,17 @@ define <2 x i8> @negate_if_true_wrong_constant(<2 x i8> %px, i1 %cond) {
   %r = mul <2 x i8> %x, %sel
   ret <2 x i8> %r
 }
+
+; (C ? (X /exact Y) : 1) * Y -> C ? X : Y
+define i32 @mul_div_select(i32 %x, i32 %y, i1 %c) {
+; CHECK-LABEL: @mul_div_select(
+; CHECK-NEXT:    [[DIV:%.*]] = udiv exact i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[C:%.*]], i32 [[DIV]], i32 1
+; CHECK-NEXT:    [[MUL:%.*]] = mul i32 [[SEL]], [[Y]]
+; CHECK-NEXT:    ret i32 [[MUL]]
+;
+  %div = udiv exact i32 %x, %y
+  %sel = select i1 %c, i32 %div, i32 1
+  %mul = mul i32 %sel, %y
+  ret i32 %mul
+}