Skip to content

Commit 08819a0

Browse files
committed
[Reassociate] Use disjoint flag to convert Or to Add.
1 parent 1241b5b commit 08819a0

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,9 +2256,10 @@ void ReassociatePass::OptimizeInst(Instruction *I) {
22562256
// with no common bits set, convert it to X+Y.
22572257
if (I->getOpcode() == Instruction::Or &&
22582258
shouldConvertOrWithNoCommonBitsToAdd(I) && !isLoadCombineCandidate(I) &&
2259-
haveNoCommonBitsSet(I->getOperand(0), I->getOperand(1),
2260-
SimplifyQuery(I->getModule()->getDataLayout(),
2261-
/*DT=*/nullptr, /*AC=*/nullptr, I))) {
2259+
(I->isDisjoint() ||
2260+
haveNoCommonBitsSet(I->getOperand(0), I->getOperand(1),
2261+
SimplifyQuery(I->getModule()->getDataLayout(),
2262+
/*DT=*/nullptr, /*AC=*/nullptr, I)))) {
22622263
Instruction *NI = convertOrWithNoCommonBitsToAdd(I);
22632264
RedoInsts.insert(I);
22642265
MadeChange = true;

llvm/test/Transforms/Reassociate/add-like-or.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ define i32 @test3(i32 %x, i32 %bit) {
5959
ret i32 %res
6060
}
6161

62+
; Test that disjoint allow reassociation.
63+
define i32 @test4(i32 %a, i32 %b) {
64+
; CHECK-LABEL: @test4(
65+
; CHECK-NEXT: [[C:%.*]] = add i32 [[A:%.*]], 1
66+
; CHECK-NEXT: [[C_PLUS_ONE:%.*]] = add i32 [[C]], [[B:%.*]]
67+
; CHECK-NEXT: ret i32 [[C_PLUS_ONE]]
68+
;
69+
%c = or disjoint i32 %a, %b
70+
%c.plus.one = add i32 %c, 1
71+
ret i32 %c.plus.one
72+
}
73+
6274
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #2
6375

6476
!0 = !{i32 0, i32 33}

0 commit comments

Comments
 (0)