[PATCH] D104193: [InstCombine] Fold (sext bool X) * (sext bool X) to zext (and X, X)
Daniil Seredkin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 18 00:14:20 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG31053338c97b: [InstCombine] Fold (sext bool X) * (sext bool X) to zext (and X, X) (authored by vdsered).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104193/new/
https://reviews.llvm.org/D104193
Files:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/mul.ll
Index: llvm/test/Transforms/InstCombine/mul.ll
===================================================================
--- llvm/test/Transforms/InstCombine/mul.ll
+++ llvm/test/Transforms/InstCombine/mul.ll
@@ -318,6 +318,76 @@
ret i32 %r
}
+define i32 @mul_bools_sext_one_use_per_op(i1 %x, i1 %y) {
+; CHECK-LABEL: @mul_bools_sext_one_use_per_op(
+; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %sx = sext i1 %x to i32
+ %sy = sext i1 %y to i32
+ %r = mul i32 %sx, %sy
+ ret i32 %r
+}
+
+define i32 @mul_bool_sext_one_user(i1 %x) {
+; CHECK-LABEL: @mul_bool_sext_one_user(
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[X:%.*]] to i32
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %sx = sext i1 %x to i32
+ %r = mul i32 %sx, %sx
+ ret i32 %r
+}
+
+define i32 @mul_bools_zext_one_use_per_op(i1 %x, i1 %y) {
+; CHECK-LABEL: @mul_bools_zext_one_use_per_op(
+; CHECK-NEXT: [[MULBOOL:%.*]] = and i1 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[MULBOOL]] to i32
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %zx = zext i1 %x to i32
+ %zy = zext i1 %y to i32
+ %r = mul i32 %zx, %zy
+ ret i32 %r
+}
+
+define i32 @mul_bool_zext_one_user(i1 %x) {
+; CHECK-LABEL: @mul_bool_zext_one_user(
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[X:%.*]] to i32
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %sx = zext i1 %x to i32
+ %r = mul i32 %sx, %sx
+ ret i32 %r
+}
+
+define i32 @mul_bool_sext_one_extra_user(i1 %x) {
+; CHECK-LABEL: @mul_bool_sext_one_extra_user(
+; CHECK-NEXT: [[SX:%.*]] = sext i1 [[X:%.*]] to i32
+; CHECK-NEXT: call void @use32(i32 [[SX]])
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[X]] to i32
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %sx = sext i1 %x to i32
+ call void @use32(i32 %sx)
+ %r = mul i32 %sx, %sx
+ ret i32 %r
+}
+
+define i32 @mul_bool_zext_one_extra_user(i1 %x) {
+; CHECK-LABEL: @mul_bool_zext_one_extra_user(
+; CHECK-NEXT: [[SX:%.*]] = zext i1 [[X:%.*]] to i32
+; CHECK-NEXT: call void @use32(i32 [[SX]])
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[X]] to i32
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %sx = zext i1 %x to i32
+ call void @use32(i32 %sx)
+ %r = mul i32 %sx, %sx
+ ret i32 %r
+}
+
define <3 x i32> @mul_bools_mixed_ext(<3 x i1> %x, <3 x i1> %y) {
; CHECK-LABEL: @mul_bools_mixed_ext(
; CHECK-NEXT: [[MULBOOL:%.*]] = and <3 x i1> [[X:%.*]], [[Y:%.*]]
Index: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -328,7 +328,7 @@
if (((match(Op0, m_ZExt(m_Value(X))) && match(Op1, m_ZExt(m_Value(Y)))) ||
(match(Op0, m_SExt(m_Value(X))) && match(Op1, m_SExt(m_Value(Y))))) &&
X->getType()->isIntOrIntVectorTy(1) && X->getType() == Y->getType() &&
- (Op0->hasOneUse() || Op1->hasOneUse())) {
+ (Op0->hasOneUse() || Op1->hasOneUse() || X == Y)) {
Value *And = Builder.CreateAnd(X, Y, "mulbool");
return CastInst::Create(Instruction::ZExt, And, I.getType());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104193.352923.patch
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210618/471c30c1/attachment.bin>
More information about the llvm-commits
mailing list