[llvm] 7896445 - [Reassociate] Use disjoint flag to convert Or to Add. (#72772)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 6 13:48:20 PST 2023
Author: Craig Topper
Date: 2023-12-06T13:48:15-08:00
New Revision: 78964457cf1bafe57a54629fafbd081452a9e528
URL: https://github.com/llvm/llvm-project/commit/78964457cf1bafe57a54629fafbd081452a9e528
DIFF: https://github.com/llvm/llvm-project/commit/78964457cf1bafe57a54629fafbd081452a9e528.diff
LOG: [Reassociate] Use disjoint flag to convert Or to Add. (#72772)
We still have to keep the noCommonBitsSet call to handle multiple reassociations in one pass. We'll lose the flag on the first reassociation.
Added:
Modified:
llvm/lib/Transforms/Scalar/Reassociate.cpp
llvm/test/Transforms/Reassociate/add-like-or.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index d3f6d24d90961..9f1b47990b736 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -2256,9 +2256,10 @@ void ReassociatePass::OptimizeInst(Instruction *I) {
// with no common bits set, convert it to X+Y.
if (I->getOpcode() == Instruction::Or &&
shouldConvertOrWithNoCommonBitsToAdd(I) && !isLoadCombineCandidate(I) &&
- haveNoCommonBitsSet(I->getOperand(0), I->getOperand(1),
- SimplifyQuery(I->getModule()->getDataLayout(),
- /*DT=*/nullptr, /*AC=*/nullptr, I))) {
+ (I->isDisjoint() ||
+ haveNoCommonBitsSet(I->getOperand(0), I->getOperand(1),
+ SimplifyQuery(I->getModule()->getDataLayout(),
+ /*DT=*/nullptr, /*AC=*/nullptr, I)))) {
Instruction *NI = convertOrWithNoCommonBitsToAdd(I);
RedoInsts.insert(I);
MadeChange = true;
diff --git a/llvm/test/Transforms/Reassociate/add-like-or.ll b/llvm/test/Transforms/Reassociate/add-like-or.ll
index 514b10b5a76b3..d88458f630bc0 100644
--- a/llvm/test/Transforms/Reassociate/add-like-or.ll
+++ b/llvm/test/Transforms/Reassociate/add-like-or.ll
@@ -59,6 +59,18 @@ define i32 @test3(i32 %x, i32 %bit) {
ret i32 %res
}
+; Test that disjoint allow reassociation.
+define i32 @test4(i32 %a, i32 %b) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT: [[C:%.*]] = add i32 [[A:%.*]], 1
+; CHECK-NEXT: [[C_PLUS_ONE:%.*]] = add i32 [[C]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[C_PLUS_ONE]]
+;
+ %c = or disjoint i32 %a, %b
+ %c.plus.one = add i32 %c, 1
+ ret i32 %c.plus.one
+}
+
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #2
!0 = !{i32 0, i32 33}
More information about the llvm-commits
mailing list