[llvm] 4c1dc65 - [InstCombine] add/adjust tests for multiply with extended bool; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 20 12:57:09 PST 2022
Author: Sanjay Patel
Date: 2022-01-20T15:57:01-05:00
New Revision: 4c1dc65015ae8ba4b7e0ac56f4d88d29e712ce25
URL: https://github.com/llvm/llvm-project/commit/4c1dc65015ae8ba4b7e0ac56f4d88d29e712ce25
DIFF: https://github.com/llvm/llvm-project/commit/4c1dc65015ae8ba4b7e0ac56f4d88d29e712ce25.diff
LOG: [InstCombine] add/adjust tests for multiply with extended bool; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/mul.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll
index 76dc39598dc7f..e99d1e9cfd181 100644
--- a/llvm/test/Transforms/InstCombine/mul.ll
+++ b/llvm/test/Transforms/InstCombine/mul.ll
@@ -103,32 +103,69 @@ define i32 @mul_bool(i32 %x, i1 %y) {
; CHECK-NEXT: ret i32 [[M]]
;
%z = zext i1 %y to i32
- %m = mul i32 %x, %z
+ %m = mul i32 %z, %x
ret i32 %m
}
-; Commute and test vector type.
-
define <2 x i32> @mul_bool_vec(<2 x i32> %x, <2 x i1> %y) {
; CHECK-LABEL: @mul_bool_vec(
; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X:%.*]], <2 x i32> zeroinitializer
; CHECK-NEXT: ret <2 x i32> [[M]]
;
%z = zext <2 x i1> %y to <2 x i32>
- %m = mul <2 x i32> %x, %z
+ %m = mul <2 x i32> %z, %x
ret <2 x i32> %m
}
-define <2 x i32> @mul_bool_vec_commute(<2 x i32> %x, <2 x i1> %y) {
+define <2 x i32> @mul_bool_vec_commute(<2 x i32> %px, <2 x i1> %y) {
; CHECK-LABEL: @mul_bool_vec_commute(
-; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X:%.*]], <2 x i32> zeroinitializer
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i32> [[PX:%.*]], [[PX]]
+; CHECK-NEXT: [[M:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i32> [[X]], <2 x i32> zeroinitializer
; CHECK-NEXT: ret <2 x i32> [[M]]
;
+ %x = mul <2 x i32> %px, %px ; thwart complexity-based canonicalization
%z = zext <2 x i1> %y to <2 x i32>
- %m = mul <2 x i32> %z, %x
+ %m = mul <2 x i32> %x, %z
ret <2 x i32> %m
}
+; X * C (when X is a sext boolean) --> X ? -C : 0
+
+define i32 @mul_sext_bool(i1 %x) {
+; CHECK-LABEL: @mul_sext_bool(
+; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i32
+; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[S]], 42
+; CHECK-NEXT: ret i32 [[M]]
+;
+ %s = sext i1 %x to i32
+ %m = mul i32 %s, 42
+ ret i32 %m
+}
+
+define i32 @mul_sext_bool_use(i1 %x) {
+; CHECK-LABEL: @mul_sext_bool_use(
+; CHECK-NEXT: [[S:%.*]] = sext i1 [[X:%.*]] to i32
+; CHECK-NEXT: call void @use32(i32 [[S]])
+; CHECK-NEXT: [[M:%.*]] = mul nsw i32 [[S]], 42
+; CHECK-NEXT: ret i32 [[M]]
+;
+ %s = sext i1 %x to i32
+ call void @use32(i32 %s)
+ %m = mul i32 %s, 42
+ ret i32 %m
+}
+
+define <2 x i8> @mul_sext_bool_vec(<2 x i1> %x) {
+; CHECK-LABEL: @mul_sext_bool_vec(
+; CHECK-NEXT: [[S:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i8>
+; CHECK-NEXT: [[M:%.*]] = mul <2 x i8> [[S]], <i8 42, i8 -128>
+; CHECK-NEXT: ret <2 x i8> [[M]]
+;
+ %s = sext <2 x i1> %x to <2 x i8>
+ %m = mul <2 x i8> %s, <i8 42, i8 -128>
+ ret <2 x i8> %m
+}
+
define <3 x i7> @mul_bools(<3 x i1> %x, <3 x i1> %y) {
; CHECK-LABEL: @mul_bools(
; CHECK-NEXT: [[MULBOOL:%.*]] = and <3 x i1> [[X:%.*]], [[Y:%.*]]
More information about the llvm-commits
mailing list