[llvm] a404acb - [NFC][InstCombine] Add some more tests for negation sinking into mul
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 13:45:37 PDT 2020
Author: Roman Lebedev
Date: 2020-08-06T23:37:17+03:00
New Revision: a404acb86af7d62390a2599bb86bba2c5f840f68
URL: https://github.com/llvm/llvm-project/commit/a404acb86af7d62390a2599bb86bba2c5f840f68
DIFF: https://github.com/llvm/llvm-project/commit/a404acb86af7d62390a2599bb86bba2c5f840f68.diff
LOG: [NFC][InstCombine] Add some more tests for negation sinking into mul
Added:
Modified:
llvm/test/Transforms/InstCombine/mul.ll
llvm/test/Transforms/InstCombine/sub-of-negatible.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll
index 94d369d6f1b7..a533e88f2193 100644
--- a/llvm/test/Transforms/InstCombine/mul.ll
+++ b/llvm/test/Transforms/InstCombine/mul.ll
@@ -1003,3 +1003,83 @@ define <2 x i32> @muladd2_vec_nonuniform_undef(<2 x i32> %a0) {
%mul = mul <2 x i32> %add, <i32 -4, i32 undef>
ret <2 x i32> %mul
}
+
+define i32 @mulmuladd2(i32 %a0, i32 %a1) {
+; CHECK-LABEL: @mulmuladd2(
+; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
+; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
+; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
+; CHECK-NEXT: ret i32 [[MUL2]]
+;
+ %add = add i32 %a0, 16
+ %mul1 = mul i32 %add, %a1
+ %mul2 = mul i32 %mul1, -4
+ ret i32 %mul2
+}
+define i32 @mulmuladd2_extrause0(i32 %a0, i32 %a1) {
+; CHECK-LABEL: @mulmuladd2_extrause0(
+; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
+; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
+; CHECK-NEXT: call void @use32(i32 [[MUL1]])
+; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
+; CHECK-NEXT: ret i32 [[MUL2]]
+;
+ %add = add i32 %a0, 16
+ %mul1 = mul i32 %add, %a1
+ call void @use32(i32 %mul1)
+ %mul2 = mul i32 %mul1, -4
+ ret i32 %mul2
+}
+define i32 @mulmuladd2_extrause1(i32 %a0, i32 %a1) {
+; CHECK-LABEL: @mulmuladd2_extrause1(
+; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
+; CHECK-NEXT: call void @use32(i32 [[ADD]])
+; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
+; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
+; CHECK-NEXT: ret i32 [[MUL2]]
+;
+ %add = add i32 %a0, 16
+ call void @use32(i32 %add)
+ %mul1 = mul i32 %add, %a1
+ %mul2 = mul i32 %mul1, -4
+ ret i32 %mul2
+}
+define i32 @mulmuladd2_extrause2(i32 %a0, i32 %a1) {
+; CHECK-LABEL: @mulmuladd2_extrause2(
+; CHECK-NEXT: [[ADD:%.*]] = add i32 [[A0:%.*]], 16
+; CHECK-NEXT: call void @use32(i32 [[ADD]])
+; CHECK-NEXT: [[MUL1:%.*]] = mul i32 [[ADD]], [[A1:%.*]]
+; CHECK-NEXT: call void @use32(i32 [[MUL1]])
+; CHECK-NEXT: [[MUL2:%.*]] = mul i32 [[MUL1]], -4
+; CHECK-NEXT: ret i32 [[MUL2]]
+;
+ %add = add i32 %a0, 16
+ call void @use32(i32 %add)
+ %mul1 = mul i32 %add, %a1
+ call void @use32(i32 %mul1)
+ %mul2 = mul i32 %mul1, -4
+ ret i32 %mul2
+}
+
+define i32 @mulnot(i32 %a0) {
+; CHECK-LABEL: @mulnot(
+; CHECK-NEXT: [[ADD:%.*]] = xor i32 [[A0:%.*]], -1
+; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[ADD]], -4
+; CHECK-NEXT: ret i32 [[MUL]]
+;
+ %add = xor i32 %a0, -1
+ %mul = mul i32 %add, -4
+ ret i32 %mul
+}
+define i32 @mulnot_extrause(i32 %a0) {
+; CHECK-LABEL: @mulnot_extrause(
+; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[A0:%.*]], -1
+; CHECK-NEXT: call void @use32(i32 [[NOT]])
+; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[NOT]], -4
+; CHECK-NEXT: ret i32 [[MUL]]
+;
+ %not = xor i32 %a0, -1
+ call void @use32(i32 %not)
+ %mul = mul i32 %not, -4
+ ret i32 %mul
+}
diff --git a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
index 43bedaa9b157..d0850107a567 100644
--- a/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
+++ b/llvm/test/Transforms/InstCombine/sub-of-negatible.ll
@@ -1113,6 +1113,19 @@ define i8 @negate_add_with_single_negatible_operand(i8 %x, i8 %y) {
%t1 = sub i8 0, %t0
ret i8 %t1
}
+; do so even if we are two levels deep
+define i8 @negate_add_with_single_negatible_operand_depth2(i8 %x, i8 %y) {
+; CHECK-LABEL: @negate_add_with_single_negatible_operand_depth2(
+; CHECK-NEXT: [[T0_NEG:%.*]] = sub i8 -21, [[X:%.*]]
+; CHECK-NEXT: [[T1_NEG:%.*]] = mul i8 [[T0_NEG]], [[Y:%.*]]
+; CHECK-NEXT: ret i8 [[T1_NEG]]
+;
+ %t0 = add i8 %x, 21
+ %t1 = mul i8 %t0, %y
+ %t2 = sub i8 0, %t1
+ ret i8 %t2
+}
+
define i8 @negate_add_with_single_negatible_operand_extrause(i8 %x, i8 %y) {
; CHECK-LABEL: @negate_add_with_single_negatible_operand_extrause(
; CHECK-NEXT: [[T0:%.*]] = add i8 [[X:%.*]], 42
More information about the llvm-commits
mailing list