Skip to content

Commit fc13f33

Browse files
committed
[Reassociate] Move Disjoint flag handling to OverflowTracking.
Move disjoint flag tracking to OverflowTracking. This enables preserving disjoint flags in Reassociate. Depends on llvm#140404
1 parent 0fa3ba7 commit fc13f33

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ bool inferAttributesFromOthers(Function &F);
563563
struct OverflowTracking {
564564
bool HasNUW = true;
565565
bool HasNSW = true;
566+
bool IsDisjoint = true;
566567

567568
// Note: At the moment, users are responsible to manage AllKnownNonNegative
568569
// and AllKnownNonZero manually. AllKnownNonNegative can be true in a case

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,13 +2870,6 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
28702870
if (auto *I = dyn_cast<Instruction>(Inv))
28712871
I->setFastMathFlags(Intersect);
28722872
NewBO->setFastMathFlags(Intersect);
2873-
} else if (Opcode == Instruction::Or) {
2874-
bool Disjoint = cast<PossiblyDisjointInst>(BO)->isDisjoint() &&
2875-
cast<PossiblyDisjointInst>(BO0)->isDisjoint();
2876-
// If `Inv` was not constant-folded, a new Instruction has been created.
2877-
if (auto *I = dyn_cast<PossiblyDisjointInst>(Inv))
2878-
I->setIsDisjoint(Disjoint);
2879-
cast<PossiblyDisjointInst>(NewBO)->setIsDisjoint(Disjoint);
28802873
} else {
28812874
OverflowTracking Flags;
28822875
Flags.AllKnownNonNegative = false;

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4368,6 +4368,8 @@ void OverflowTracking::mergeFlags(Instruction &I) {
43684368
HasNUW &= I.hasNoUnsignedWrap();
43694369
HasNSW &= I.hasNoSignedWrap();
43704370
}
4371+
if (auto *DisjointOp = dyn_cast<PossiblyDisjointInst>(&I))
4372+
IsDisjoint &= DisjointOp->isDisjoint();
43714373
}
43724374

43734375
void OverflowTracking::applyFlags(Instruction &I) {
@@ -4379,4 +4381,6 @@ void OverflowTracking::applyFlags(Instruction &I) {
43794381
if (HasNSW && (AllKnownNonNegative || HasNUW))
43804382
I.setHasNoSignedWrap();
43814383
}
4384+
if (auto *DisjointOp = dyn_cast<PossiblyDisjointInst>(&I))
4385+
DisjointOp->setIsDisjoint(IsDisjoint);
43824386
}

llvm/test/Transforms/Reassociate/or-disjoint.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
define i16 @or_disjoint_both(i16 %a, i16 %b) {
66
; CHECK-LABEL: @or_disjoint_both(
7-
; CHECK-NEXT: [[OR_1:%.*]] = or i16 [[A:%.*]], 1
8-
; CHECK-NEXT: [[OR_2:%.*]] = or i16 [[OR_1]], [[B:%.*]]
7+
; CHECK-NEXT: [[OR_1:%.*]] = or disjoint i16 [[A:%.*]], 1
8+
; CHECK-NEXT: [[OR_2:%.*]] = or disjoint i16 [[OR_1]], [[B:%.*]]
99
; CHECK-NEXT: ret i16 [[OR_2]]
1010
;
1111
%or.1 = or disjoint i16 %b, %a

0 commit comments

Comments
 (0)