[llvm] 0cdacd5 - [DomTree] Fix root attachment in runDFS() (#73148)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 4 00:24:18 PST 2023
Author: Nikita Popov
Date: 2023-12-04T09:24:13+01:00
New Revision: 0cdacd5f492991362bfc8e252673aafdb9651322
URL: https://github.com/llvm/llvm-project/commit/0cdacd5f492991362bfc8e252673aafdb9651322
DIFF: https://github.com/llvm/llvm-project/commit/0cdacd5f492991362bfc8e252673aafdb9651322.diff
LOG: [DomTree] Fix root attachment in runDFS() (#73148)
Currently, runDFS() only sets the Parent of the DFS root if it is
already in the NodeToInfo map. This doesn't matter if we're running DFS
on the DT root, which doesn't have a parent anyway. However, when
running on PDT roots, this means we end up keeping the parent at 0,
rather than setting it to 1 for the virtual PDT root. Because the
virtual root (nullptr) has the same value as the dummy value in
NumToNode (nullptr) this happens to work out by accident right now.
I believe we should always be setting the parent in runDFS(), and adjust
AttachToNum in doFullDFSWalk() to be 1 (the virtual root) for PDTs.
Added:
Modified:
llvm/include/llvm/Support/GenericDomTreeConstruction.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
index 48a59491e486d..29b5f9159c68e 100644
--- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -181,7 +181,7 @@ struct SemiNCAInfo {
const NodeOrderMap *SuccOrder = nullptr) {
assert(V);
SmallVector<NodePtr, 64> WorkList = {V};
- if (NodeToInfo.count(V) != 0) NodeToInfo[V].Parent = AttachToNum;
+ NodeToInfo[V].Parent = AttachToNum;
while (!WorkList.empty()) {
const NodePtr BB = WorkList.pop_back_val();
@@ -299,7 +299,8 @@ struct SemiNCAInfo {
// during path compression in Eval.
for (unsigned i = 2; i < NextDFSNum; ++i) {
auto &WInfo = *NumToInfo[i];
- const unsigned SDomNum = NodeToInfo[NumToNode[WInfo.Semi]].DFSNum;
+ assert(WInfo.Semi != 0);
+ const unsigned SDomNum = NumToInfo[WInfo.Semi]->DFSNum;
NodePtr WIDomCandidate = WInfo.IDom;
while (true) {
auto &WIDomCandidateInfo = NodeToInfo.find(WIDomCandidate)->second;
@@ -548,7 +549,7 @@ struct SemiNCAInfo {
addVirtualRoot();
unsigned Num = 1;
- for (const NodePtr Root : DT.Roots) Num = runDFS(Root, Num, DC, 0);
+ for (const NodePtr Root : DT.Roots) Num = runDFS(Root, Num, DC, 1);
}
static void CalculateFromScratch(DomTreeT &DT, BatchUpdatePtr BUI) {
More information about the llvm-commits
mailing list