Skip to content

Commit 03cf88f

Browse files
nikictstellar
authored andcommitted
[DSE] Extract a common PDT check (NFC)
1 parent ee0ae47 commit 03cf88f

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,54 +1508,49 @@ struct DSEState {
15081508
CommonPred = PDT.findNearestCommonDominator(CommonPred, BB);
15091509
}
15101510

1511-
// If CommonPred is in the set of killing blocks, just check if it
1512-
// post-dominates MaybeDeadAccess.
1513-
if (KillingBlocks.count(CommonPred)) {
1514-
if (PDT.dominates(CommonPred, MaybeDeadAccess->getBlock()))
1515-
return {MaybeDeadAccess};
1516-
return None;
1517-
}
1518-
15191511
// If the common post-dominator does not post-dominate MaybeDeadAccess,
15201512
// there is a path from MaybeDeadAccess to an exit not going through a
15211513
// killing block.
1522-
if (PDT.dominates(CommonPred, MaybeDeadAccess->getBlock())) {
1523-
SetVector<BasicBlock *> WorkList;
1524-
1525-
// If CommonPred is null, there are multiple exits from the function.
1526-
// They all have to be added to the worklist.
1527-
if (CommonPred)
1528-
WorkList.insert(CommonPred);
1529-
else
1530-
for (BasicBlock *R : PDT.roots())
1531-
WorkList.insert(R);
1532-
1533-
NumCFGTries++;
1534-
// Check if all paths starting from an exit node go through one of the
1535-
// killing blocks before reaching MaybeDeadAccess.
1536-
for (unsigned I = 0; I < WorkList.size(); I++) {
1537-
NumCFGChecks++;
1538-
BasicBlock *Current = WorkList[I];
1539-
if (KillingBlocks.count(Current))
1540-
continue;
1541-
if (Current == MaybeDeadAccess->getBlock())
1542-
return None;
1514+
if (!PDT.dominates(CommonPred, MaybeDeadAccess->getBlock()))
1515+
return None;
15431516

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

1549-
for (BasicBlock *Pred : predecessors(Current))
1550-
WorkList.insert(Pred);
1521+
SetVector<BasicBlock *> WorkList;
15511522

1552-
if (WorkList.size() >= MemorySSAPathCheckLimit)
1553-
return None;
1554-
}
1555-
NumCFGSuccess++;
1556-
return {MaybeDeadAccess};
1523+
// If CommonPred is null, there are multiple exits from the function.
1524+
// They all have to be added to the worklist.
1525+
if (CommonPred)
1526+
WorkList.insert(CommonPred);
1527+
else
1528+
for (BasicBlock *R : PDT.roots())
1529+
WorkList.insert(R);
1530+
1531+
NumCFGTries++;
1532+
// Check if all paths starting from an exit node go through one of the
1533+
// killing blocks before reaching MaybeDeadAccess.
1534+
for (unsigned I = 0; I < WorkList.size(); I++) {
1535+
NumCFGChecks++;
1536+
BasicBlock *Current = WorkList[I];
1537+
if (KillingBlocks.count(Current))
1538+
continue;
1539+
if (Current == MaybeDeadAccess->getBlock())
1540+
return None;
1541+
1542+
// MaybeDeadAccess is reachable from the entry, so we don't have to
1543+
// explore unreachable blocks further.
1544+
if (!DT.isReachableFromEntry(Current))
1545+
continue;
1546+
1547+
for (BasicBlock *Pred : predecessors(Current))
1548+
WorkList.insert(Pred);
1549+
1550+
if (WorkList.size() >= MemorySSAPathCheckLimit)
1551+
return None;
15571552
}
1558-
return None;
1553+
NumCFGSuccess++;
15591554
}
15601555

15611556
// No aliasing MemoryUses of MaybeDeadAccess found, MaybeDeadAccess is

0 commit comments

Comments
 (0)