Skip to content

Commit

Permalink
[Attributor][FIX] Track change status for AAIsDead properly
Browse files Browse the repository at this point in the history
If we add a new live edge we need to indicate a change or otherwise the
new live block is not shown to users. Similarly, new known dead ends and
a changed `ToBeExploredFrom` set need to cause us to return CHANGED.
  • Loading branch information
jdoerfert committed Jul 27, 2021
1 parent ebe817f commit 8befd05
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Expand Up @@ -3836,10 +3836,8 @@ ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {

// Fast forward for uninteresting instructions. We could look for UB here
// though.
while (!I->isTerminator() && !isa<CallBase>(I)) {
Change = ChangeStatus::CHANGED;
while (!I->isTerminator() && !isa<CallBase>(I))
I = I->getNextNode();
}

AliveSuccessors.clear();

Expand Down Expand Up @@ -3872,11 +3870,11 @@ ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {

if (UsedAssumedInformation) {
NewToBeExploredFrom.insert(I);
} else {
Change = ChangeStatus::CHANGED;
if (AliveSuccessors.empty() ||
(I->isTerminator() && AliveSuccessors.size() < I->getNumSuccessors()))
KnownDeadEnds.insert(I);
} else if (AliveSuccessors.empty() ||
(I->isTerminator() &&
AliveSuccessors.size() < I->getNumSuccessors())) {
if (KnownDeadEnds.insert(I))
Change = ChangeStatus::CHANGED;
}

LLVM_DEBUG(dbgs() << "[AAIsDead] #AliveSuccessors: "
Expand All @@ -3890,15 +3888,23 @@ ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) {
Worklist.push_back(AliveSuccessor);
} else {
// record the assumed live edge
AssumedLiveEdges.insert(
std::make_pair(I->getParent(), AliveSuccessor->getParent()));
auto Edge = std::make_pair(I->getParent(), AliveSuccessor->getParent());
if (AssumedLiveEdges.insert(Edge).second)
Change = ChangeStatus::CHANGED;
if (assumeLive(A, *AliveSuccessor->getParent()))
Worklist.push_back(AliveSuccessor);
}
}
}

ToBeExploredFrom = std::move(NewToBeExploredFrom);
// Check if the content of ToBeExploredFrom changed, ignore the order.
if (NewToBeExploredFrom.size() != ToBeExploredFrom.size() ||
llvm::any_of(NewToBeExploredFrom, [&](const Instruction *I) {
return !ToBeExploredFrom.count(I);
})) {
Change = ChangeStatus::CHANGED;
ToBeExploredFrom = std::move(NewToBeExploredFrom);
}

// If we know everything is live there is no need to query for liveness.
// Instead, indicating a pessimistic fixpoint will cause the state to be
Expand Down

0 comments on commit 8befd05

Please sign in to comment.