From 6e312388b6f861067285bac45d90bd92b508608c Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 4 Oct 2019 20:54:14 +0000 Subject: [PATCH] [InstCombine] add tests for fneg disguised as fmul; NFC llvm-svn: 373788 --- llvm/test/Transforms/InstCombine/fmul.ll | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/fmul.ll b/llvm/test/Transforms/InstCombine/fmul.ll index d448679..5ab6d93 100644 --- a/llvm/test/Transforms/InstCombine/fmul.ll +++ b/llvm/test/Transforms/InstCombine/fmul.ll @@ -991,3 +991,77 @@ define double @fmul_negated_constant_expression(double %x) { %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> , [[PX:%.*]] +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x double> , <2 x double> +; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]] +; CHECK-NEXT: ret <2 x double> [[R]] +; + %x = fdiv <2 x double> , %px ; thwart complexity-based canonicalization + %sel = select i1 %cond, <2 x double> , <2 x double> + %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> , [[PX:%.*]] +; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[COND:%.*]], <2 x double> , <2 x double> +; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]] +; CHECK-NEXT: ret <2 x double> [[R]] +; + %x = fdiv <2 x double> , %px ; thwart complexity-based canonicalization + %sel = select <2 x i1> %cond, <2 x double> , <2 x double> + %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> , [[PX:%.*]] +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x double> , <2 x double> +; CHECK-NEXT: [[R:%.*]] = fmul <2 x double> [[X]], [[SEL]] +; CHECK-NEXT: ret <2 x double> [[R]] +; + %x = fdiv <2 x double> , %px ; thwart complexity-based canonicalization + %sel = select i1 %cond, <2 x double> , <2 x double> + %r = fmul <2 x double> %x, %sel + ret <2 x double> %r +} -- 2.7.4