From 8913882fa2a2332dcb369ad4de44307ffd41f56e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 30 Sep 2019 15:43:27 +0000 Subject: [PATCH] [InstCombine] add tests for negate disguised as mul; NFC llvm-svn: 373222 --- llvm/test/Transforms/InstCombine/mul.ll | 74 +++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll index b1dc9d51332d..37f05d222c96 100644 --- a/llvm/test/Transforms/InstCombine/mul.ll +++ b/llvm/test/Transforms/InstCombine/mul.ll @@ -517,3 +517,77 @@ define i64 @test_mul_canonicalize_neg_is_not_undone(i64 %L1) { %B4 = mul i64 %B8, %L1 ret i64 %B4 } + +define i32 @negate_if_true(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_true( +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i32 -1, i32 1 +; CHECK-NEXT: [[R:%.*]] = mul i32 [[SEL]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %sel = select i1 %cond, i32 -1, i32 1 + %r = mul i32 %sel, %x + ret i32 %r +} + +define i32 @negate_if_false(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_false( +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i32 1, i32 -1 +; CHECK-NEXT: [[R:%.*]] = mul i32 [[SEL]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %sel = select i1 %cond, i32 1, i32 -1 + %r = mul i32 %sel, %x + ret i32 %r +} + +define <2 x i8> @negate_if_true_commute(<2 x i8> %px, i1 %cond) { +; CHECK-LABEL: @negate_if_true_commute( +; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> , [[PX:%.*]] +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x i8> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[X]], [[SEL]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %x = sdiv <2 x i8> , %px ; thwart complexity-based canonicalization + %sel = select i1 %cond, <2 x i8> , <2 x i8> + %r = mul <2 x i8> %x, %sel + ret <2 x i8> %r +} + +define <2 x i8> @negate_if_false_commute(<2 x i8> %px, <2 x i1> %cond) { +; CHECK-LABEL: @negate_if_false_commute( +; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> , [[PX:%.*]] +; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i8> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[X]], [[SEL]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %x = sdiv <2 x i8> , %px ; thwart complexity-based canonicalization + %sel = select <2 x i1> %cond, <2 x i8> , <2 x i8> + %r = mul <2 x i8> %x, %sel + ret <2 x i8> %r +} + +define i32 @negate_if_true_extra_use(i32 %x, i1 %cond) { +; CHECK-LABEL: @negate_if_true_extra_use( +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i32 -1, i32 1 +; CHECK-NEXT: call void @use32(i32 [[SEL]]) +; CHECK-NEXT: [[R:%.*]] = mul i32 [[SEL]], [[X:%.*]] +; CHECK-NEXT: ret i32 [[R]] +; + %sel = select i1 %cond, i32 -1, i32 1 + call void @use32(i32 %sel) + %r = mul i32 %sel, %x + ret i32 %r +} + +define <2 x i8> @negate_if_true_wrong_constant(<2 x i8> %px, i1 %cond) { +; CHECK-LABEL: @negate_if_true_wrong_constant( +; CHECK-NEXT: [[X:%.*]] = sdiv <2 x i8> , [[PX:%.*]] +; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], <2 x i8> , <2 x i8> +; CHECK-NEXT: [[R:%.*]] = mul <2 x i8> [[X]], [[SEL]] +; CHECK-NEXT: ret <2 x i8> [[R]] +; + %x = sdiv <2 x i8> , %px ; thwart complexity-based canonicalization + %sel = select i1 %cond, <2 x i8> , <2 x i8> + %r = mul <2 x i8> %x, %sel + ret <2 x i8> %r +} -- GitLab