Skip to content

Commit f534018

Browse files
committed
[LICM] Preserve Disjoint flag on OR when hoisting.
Update hoistBOAssociation to preserve Disjoint flags on the newly created instructions if both ORs are disjoint. Fixes #139625.
1 parent a31fa0e commit f534018

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,12 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
28772877
if (auto *I = dyn_cast<Instruction>(Inv))
28782878
I->setFastMathFlags(Intersect);
28792879
NewBO->setFastMathFlags(Intersect);
2880+
} else if (Opcode == Instruction::Or) {
2881+
bool Disjoint = cast<PossiblyDisjointInst>(BO)->isDisjoint() &&
2882+
cast<PossiblyDisjointInst>(BO0)->isDisjoint();
2883+
if (auto *I = dyn_cast<PossiblyDisjointInst>(Inv))
2884+
I->setIsDisjoint(Disjoint);
2885+
cast<PossiblyDisjointInst>(NewBO)->setIsDisjoint(Disjoint);
28802886
}
28812887

28822888
BO->replaceAllUsesWith(NewBO);

llvm/test/Transforms/LICM/hoist-binop.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,11 @@ loop:
727727
define void @or_all_disjoint(i64 %c1, i64 %c2) {
728728
; CHECK-LABEL: @or_all_disjoint(
729729
; CHECK-NEXT: entry:
730-
; CHECK-NEXT: [[INVARIANT_OP:%.*]] = or i64 [[C1:%.*]], [[C2:%.*]]
730+
; CHECK-NEXT: [[INVARIANT_OP:%.*]] = or disjoint i64 [[C1:%.*]], [[C2:%.*]]
731731
; CHECK-NEXT: br label [[LOOP:%.*]]
732732
; CHECK: loop:
733733
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT_REASS:%.*]], [[LOOP]] ]
734-
; CHECK-NEXT: [[INDEX_NEXT_REASS]] = or i64 [[INDEX]], [[INVARIANT_OP]]
734+
; CHECK-NEXT: [[INDEX_NEXT_REASS]] = or disjoint i64 [[INDEX]], [[INVARIANT_OP]]
735735
; CHECK-NEXT: br label [[LOOP]]
736736
;
737737
entry:

0 commit comments

Comments
 (0)