[llvm] 8ccca3f - [InstCombine] adjust tests for mul+add common factor; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 14:54:05 PDT 2022
Author: Sanjay Patel
Date: 2022-08-23T17:53:53-04:00
New Revision: 8ccca3f3a4982970eecbb4fc8513cd26a585ec36
URL: https://github.com/llvm/llvm-project/commit/8ccca3f3a4982970eecbb4fc8513cd26a585ec36
DIFF: https://github.com/llvm/llvm-project/commit/8ccca3f3a4982970eecbb4fc8513cd26a585ec36.diff
LOG: [InstCombine] adjust tests for mul+add common factor; NFC
The existing tests were added with 2880d7b9e4c9a0, but
discussion in D132412 suggests that we should start
with a simpler pattern (the more complicated pattern
may not be a real problem).
Added:
Modified:
llvm/test/Transforms/InstCombine/add.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll
index 523f5a97cf71a..1289ebe299355 100644
--- a/llvm/test/Transforms/InstCombine/add.ll
+++ b/llvm/test/Transforms/InstCombine/add.ll
@@ -1756,136 +1756,65 @@ define i32 @add_add_add_commute3(i32 %A, i32 %B, i32 %C, i32 %D) {
ret i32 %G
}
-define i8 @mul_add_common_factor_commute1(i8 %x, i8 %y, i8 %z) {
+define i8 @mul_add_common_factor_commute1(i8 %x, i8 %y) {
; CHECK-LABEL: @mul_add_common_factor_commute1(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[M]], [[A]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: [[M:%.*]] = mul nsw i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[M]], [[X]]
+; CHECK-NEXT: ret i8 [[A]]
;
- %m = mul i8 %x, %y
- %a = add i8 %x, %z
- %r = add i8 %m, %a
- ret i8 %r
+ %m = mul nsw i8 %x, %y
+ %a = add nsw i8 %m, %x
+ ret i8 %a
}
-define i8 @mul_add_common_factor_commute2(i8 %x, i8 %y, i8 %z) {
+define <2 x i8> @mul_add_common_factor_commute2(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @mul_add_common_factor_commute2(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[M]], [[A]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: [[M:%.*]] = mul nuw <2 x i8> [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[A:%.*]] = add nuw <2 x i8> [[M]], [[X]]
+; CHECK-NEXT: ret <2 x i8> [[A]]
;
- %m = mul i8 %y, %x
- %a = add i8 %x, %z
- %r = add i8 %m, %a
- ret i8 %r
+ %m = mul nuw <2 x i8> %y, %x
+ %a = add nuw <2 x i8> %m, %x
+ ret <2 x i8> %a
}
-define i8 @mul_add_common_factor_commute3(i8 %x, i8 %y, i8 %z) {
+define i8 @mul_add_common_factor_commute3(i8 %p, i8 %y) {
; CHECK-LABEL: @mul_add_common_factor_commute3(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], 42
-; CHECK-NEXT: [[A:%.*]] = add i8 [[Z:%.*]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[M]], [[A]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: [[X:%.*]] = mul i8 [[P:%.*]], [[P]]
+; CHECK-NEXT: [[M:%.*]] = mul nuw i8 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[A]]
;
- %m = mul i8 %x, 42
- %a = add i8 %z, %x
- %r = add i8 %m, %a
- ret i8 %r
+ %x = mul i8 %p, %p ; thwart complexity-based canonicalization
+ %m = mul nuw i8 %x, %y
+ %a = add nsw i8 %x, %m
+ ret i8 %a
}
-define <2 x i8> @mul_add_common_factor_commute4(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {
+define i8 @mul_add_common_factor_commute4(i8 %p, i8 %q) {
; CHECK-LABEL: @mul_add_common_factor_commute4(
-; CHECK-NEXT: [[M:%.*]] = mul <2 x i8> [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[Z:%.*]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[M]], [[A]]
-; CHECK-NEXT: ret <2 x i8> [[R]]
+; CHECK-NEXT: [[X:%.*]] = mul i8 [[P:%.*]], [[P]]
+; CHECK-NEXT: [[Y:%.*]] = mul i8 [[Q:%.*]], [[Q]]
+; CHECK-NEXT: [[M:%.*]] = mul nsw i8 [[Y]], [[X]]
+; CHECK-NEXT: [[A:%.*]] = add nuw i8 [[X]], [[M]]
+; CHECK-NEXT: ret i8 [[A]]
;
- %m = mul <2 x i8> %y, %x
- %a = add <2 x i8> %z, %x
- %r = add <2 x i8> %m, %a
- ret <2 x i8> %r
+ %x = mul i8 %p, %p ; thwart complexity-based canonicalization
+ %y = mul i8 %q, %q ; thwart complexity-based canonicalization
+ %m = mul nsw i8 %y, %x
+ %a = add nuw i8 %x, %m
+ ret i8 %a
}
-define i8 @mul_add_common_factor_commute5(i8 %x, i8 %y, i8 %z) {
-; CHECK-LABEL: @mul_add_common_factor_commute5(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], 43
-; CHECK-NEXT: [[R:%.*]] = add i8 [[A]], [[M]]
-; CHECK-NEXT: ret i8 [[R]]
-;
- %m = mul i8 %x, %y
- %a = add i8 %x, 43
- %r = add i8 %a, %m
- ret i8 %r
-}
-
-define i8 @mul_add_common_factor_commute6(i8 %x, i8 %y, i8 %z) {
-; CHECK-LABEL: @mul_add_common_factor_commute6(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[A]], [[M]]
-; CHECK-NEXT: ret i8 [[R]]
-;
- %m = mul i8 %y, %x
- %a = add i8 %x, %z
- %r = add i8 %a, %m
- ret i8 %r
-}
-
-define i8 @mul_add_common_factor_commute7(i8 %x, i8 %y, i8 %z) {
-; CHECK-LABEL: @mul_add_common_factor_commute7(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[Z:%.*]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[A]], [[M]]
-; CHECK-NEXT: ret i8 [[R]]
-;
- %m = mul i8 %x, %y
- %a = add i8 %z, %x
- %r = add i8 %a, %m
- ret i8 %r
-}
-
-define i8 @mul_add_common_factor_commute8(i8 %x, i8 %y, i8 %z) {
-; CHECK-LABEL: @mul_add_common_factor_commute8(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[Y:%.*]], [[X:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[Z:%.*]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[A]], [[M]]
-; CHECK-NEXT: ret i8 [[R]]
-;
- %m = mul i8 %y, %x
- %a = add i8 %z, %x
- %r = add i8 %a, %m
- ret i8 %r
-}
-
-define i8 @mul_add_common_factor_use1(i8 %x, i8 %y, i8 %z) {
-; CHECK-LABEL: @mul_add_common_factor_use1(
+define i8 @mul_add_common_factor_use(i8 %x, i8 %y) {
+; CHECK-LABEL: @mul_add_common_factor_use(
; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: call void @use(i8 [[M]])
-; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = add i8 [[M]], [[A]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: [[A:%.*]] = add i8 [[M]], [[X]]
+; CHECK-NEXT: ret i8 [[A]]
;
%m = mul i8 %x, %y
call void @use(i8 %m)
- %a = add i8 %x, %z
- %r = add i8 %m, %a
- ret i8 %r
-}
-
-define i8 @mul_add_common_factor_use2(i8 %x, i8 %y, i8 %z) {
-; CHECK-LABEL: @mul_add_common_factor_use2(
-; CHECK-NEXT: [[M:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[A:%.*]] = add i8 [[X]], [[Z:%.*]]
-; CHECK-NEXT: call void @use(i8 [[A]])
-; CHECK-NEXT: [[R:%.*]] = add i8 [[M]], [[A]]
-; CHECK-NEXT: ret i8 [[R]]
-;
- %m = mul i8 %x, %y
- %a = add i8 %x, %z
- call void @use(i8 %a)
- %r = add i8 %m, %a
- ret i8 %r
+ %a = add i8 %m, %x
+ ret i8 %a
}
More information about the llvm-commits
mailing list