[llvm] [InstCombine] Use disjoint flag instead of calling haveNoCommonBitsSet. (PR #74222)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 3 11:29:18 PST 2023
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/74222
>From d53d78f7f09035b4bfd98256b77f9334e04533d4 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sat, 2 Dec 2023 19:50:29 -0800
Subject: [PATCH 1/2] [InstCombine] Use disjoint flag instead of calling
haveNoCommonBitsSet.
---
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 7379bdf93169e..481fcdf181946 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -3395,7 +3395,7 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
// or (mul X, Y), X --> add (mul X, Y), X --> mul X, (Y + 1)
if (match(&I,
m_c_Or(m_OneUse(m_Mul(m_Value(X), m_Value(Y))), m_Deferred(X))) &&
- haveNoCommonBitsSet(Op0, Op1, DL)) {
+ cast<PossiblyDisjointInst>(I).isDisjoint()) {
Value *IncrementY = Builder.CreateAdd(Y, ConstantInt::get(Ty, 1));
return BinaryOperator::CreateMul(X, IncrementY);
}
>From d5a6a140c3096fb416d01c8c47e1894058242e8f Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sun, 3 Dec 2023 00:58:11 -0800
Subject: [PATCH 2/2] fixup! Add test cases with disjoint flag.
---
llvm/test/Transforms/InstCombine/or.ll | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll
index 8bf8c6fcd928b..fd415682b67f3 100644
--- a/llvm/test/Transforms/InstCombine/or.ll
+++ b/llvm/test/Transforms/InstCombine/or.ll
@@ -1511,6 +1511,27 @@ define <2 x i12> @mul_no_common_bits_commute(<2 x i12> %p) {
ret <2 x i12> %r
}
+define i32 @mul_no_common_bits_disjoint(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_no_common_bits_disjoint(
+; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[Y:%.*]], 1
+; CHECK-NEXT: [[R:%.*]] = mul i32 [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %m = mul i32 %x, %y
+ %r = or disjoint i32 %m, %x
+ ret i32 %r
+}
+
+define i32 @mul_no_common_bits_const_op_disjoint(i32 %x, i32 %y) {
+; CHECK-LABEL: @mul_no_common_bits_const_op_disjoint(
+; CHECK-NEXT: [[R:%.*]] = mul i32 [[X:%.*]], 25
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %m = mul i32 %x, 24
+ %r = or disjoint i32 %m, %x
+ ret i32 %r
+}
+
; negative test - extra use requires extra instructions
define i32 @mul_no_common_bits_uses(i32 %p1, i32 %p2) {
More information about the llvm-commits
mailing list