Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/Transforms/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ bool inferAttributesFromOthers(Function &F);
struct OverflowTracking {
bool HasNUW = true;
bool HasNSW = true;
bool IsDisjoint = true;

// Note: At the moment, users are responsible to manage AllKnownNonNegative
// and AllKnownNonZero manually. AllKnownNonNegative can be true in a case
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2870,13 +2870,6 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
if (auto *I = dyn_cast<Instruction>(Inv))
I->setFastMathFlags(Intersect);
NewBO->setFastMathFlags(Intersect);
} else if (Opcode == Instruction::Or) {
bool Disjoint = cast<PossiblyDisjointInst>(BO)->isDisjoint() &&
cast<PossiblyDisjointInst>(BO0)->isDisjoint();
// If `Inv` was not constant-folded, a new Instruction has been created.
if (auto *I = dyn_cast<PossiblyDisjointInst>(Inv))
I->setIsDisjoint(Disjoint);
cast<PossiblyDisjointInst>(NewBO)->setIsDisjoint(Disjoint);
} else {
OverflowTracking Flags;
Flags.AllKnownNonNegative = false;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4368,6 +4368,8 @@ void OverflowTracking::mergeFlags(Instruction &I) {
HasNUW &= I.hasNoUnsignedWrap();
HasNSW &= I.hasNoSignedWrap();
}
if (auto *DisjointOp = dyn_cast<PossiblyDisjointInst>(&I))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a really subtle usage error - imagine you call mergeFlags on first an add, and then a or. Do we need to have overflow tracking keep track of the instruction opcode it's being used on? Or alternative, promote the disjoint to the corresponding meaning on the add (in my previous example)?

(This is okay as a follow up, the current usage doesn't hit this case.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I put up #141231 to add an assert, thanks!

IsDisjoint &= DisjointOp->isDisjoint();
}

void OverflowTracking::applyFlags(Instruction &I) {
Expand All @@ -4379,4 +4381,6 @@ void OverflowTracking::applyFlags(Instruction &I) {
if (HasNSW && (AllKnownNonNegative || HasNUW))
I.setHasNoSignedWrap();
}
if (auto *DisjointOp = dyn_cast<PossiblyDisjointInst>(&I))
DisjointOp->setIsDisjoint(IsDisjoint);
}
4 changes: 2 additions & 2 deletions llvm/test/Transforms/Reassociate/or-disjoint.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

define i16 @or_disjoint_both(i16 %a, i16 %b) {
; CHECK-LABEL: @or_disjoint_both(
; CHECK-NEXT: [[OR_1:%.*]] = or i16 [[A:%.*]], 1
; CHECK-NEXT: [[OR_2:%.*]] = or i16 [[OR_1]], [[B:%.*]]
; CHECK-NEXT: [[OR_1:%.*]] = or disjoint i16 [[A:%.*]], 1
; CHECK-NEXT: [[OR_2:%.*]] = or disjoint i16 [[OR_1]], [[B:%.*]]
; CHECK-NEXT: ret i16 [[OR_2]]
;
%or.1 = or disjoint i16 %b, %a
Expand Down