Skip to content

Commit

Permalink
[DSE] Extract a common PDT check (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic authored and tstellar committed Feb 28, 2022
1 parent ee0ae47 commit 03cf88f
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
Expand Up @@ -1508,54 +1508,49 @@ struct DSEState {
CommonPred = PDT.findNearestCommonDominator(CommonPred, BB);
}

// If CommonPred is in the set of killing blocks, just check if it
// post-dominates MaybeDeadAccess.
if (KillingBlocks.count(CommonPred)) {
if (PDT.dominates(CommonPred, MaybeDeadAccess->getBlock()))
return {MaybeDeadAccess};
return None;
}

// If the common post-dominator does not post-dominate MaybeDeadAccess,
// there is a path from MaybeDeadAccess to an exit not going through a
// killing block.
if (PDT.dominates(CommonPred, MaybeDeadAccess->getBlock())) {
SetVector<BasicBlock *> WorkList;

// If CommonPred is null, there are multiple exits from the function.
// They all have to be added to the worklist.
if (CommonPred)
WorkList.insert(CommonPred);
else
for (BasicBlock *R : PDT.roots())
WorkList.insert(R);

NumCFGTries++;
// Check if all paths starting from an exit node go through one of the
// killing blocks before reaching MaybeDeadAccess.
for (unsigned I = 0; I < WorkList.size(); I++) {
NumCFGChecks++;
BasicBlock *Current = WorkList[I];
if (KillingBlocks.count(Current))
continue;
if (Current == MaybeDeadAccess->getBlock())
return None;
if (!PDT.dominates(CommonPred, MaybeDeadAccess->getBlock()))
return None;

// MaybeDeadAccess is reachable from the entry, so we don't have to
// explore unreachable blocks further.
if (!DT.isReachableFromEntry(Current))
continue;
// If CommonPred itself is in the set of killing blocks, we're done.
if (KillingBlocks.count(CommonPred))
return {MaybeDeadAccess};

for (BasicBlock *Pred : predecessors(Current))
WorkList.insert(Pred);
SetVector<BasicBlock *> WorkList;

if (WorkList.size() >= MemorySSAPathCheckLimit)
return None;
}
NumCFGSuccess++;
return {MaybeDeadAccess};
// If CommonPred is null, there are multiple exits from the function.
// They all have to be added to the worklist.
if (CommonPred)
WorkList.insert(CommonPred);
else
for (BasicBlock *R : PDT.roots())
WorkList.insert(R);

NumCFGTries++;
// Check if all paths starting from an exit node go through one of the
// killing blocks before reaching MaybeDeadAccess.
for (unsigned I = 0; I < WorkList.size(); I++) {
NumCFGChecks++;
BasicBlock *Current = WorkList[I];
if (KillingBlocks.count(Current))
continue;
if (Current == MaybeDeadAccess->getBlock())
return None;

// MaybeDeadAccess is reachable from the entry, so we don't have to
// explore unreachable blocks further.
if (!DT.isReachableFromEntry(Current))
continue;

for (BasicBlock *Pred : predecessors(Current))
WorkList.insert(Pred);

if (WorkList.size() >= MemorySSAPathCheckLimit)
return None;
}
return None;
NumCFGSuccess++;
}

// No aliasing MemoryUses of MaybeDeadAccess found, MaybeDeadAccess is
Expand Down

0 comments on commit 03cf88f

Please sign in to comment.