[llvm] [DomTree] Remove unnecessary domtree level check in SemiNCA (NFC) (PR #73107)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 03:38:42 PST 2023


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/73107

runSemiNCA() currently checks that the ReverseChildren are below MinLevel in the DT, which is used when performing incremental updates.

However, ReverseChildren is populated during runDFS with only the predecessors that are part of that DFS walk, which will itself be level limited in the relevant cases. As such, I don't believe that this should be checked during runSemiNCA().

This code probably dates back to a time when predecessors were not cached during runDFS and as such not limited to the visited subtree only.

>From a2073d5a18decdbd60b47f000949c70f5cba856b Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 22 Nov 2023 12:06:03 +0100
Subject: [PATCH] [DomTree] Remove unnecessary domtree level check in SemiNCA
 (NFC)

runSemiNCA() currently checks that the ReverseChildren are below
MinLevel in the DT, which is used when performing incremental
updates.

However, ReverseChildren is populated during runDFS with only
the predecessors that are part of that DFS walk, which will itself
be level limited in the relevant cases. As such, I don't believe
that this should be checked during runSemiNCA().

This code probably dates back to a time when predecessors were
run cached during runDFS and as such not limited to the visited
subtree only.
---
 .../include/llvm/Support/GenericDomTreeConstruction.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
index 6564f98ab0234b0..ce893dbda27acd3 100644
--- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -268,7 +268,7 @@ struct SemiNCAInfo {
   }
 
   // This function requires DFS to be run before calling it.
-  void runSemiNCA(DomTreeT &DT, const unsigned MinLevel = 0) {
+  void runSemiNCA(DomTreeT &DT) {
     const unsigned NextDFSNum(NumToNode.size());
     // Initialize IDoms to spanning tree parents.
     for (unsigned i = 1; i < NextDFSNum; ++i) {
@@ -289,11 +289,6 @@ struct SemiNCAInfo {
         assert(NodeToInfo.contains(N) &&
                "ReverseChildren should not contain unreachable predecessors");
 
-        const TreeNodePtr TN = DT.getNode(N);
-        // Skip predecessors whose level is above the subtree we are processing.
-        if (TN && TN->getLevel() < MinLevel)
-          continue;
-
         unsigned SemiU = NodeToInfo[eval(N, i + 1, EvalStack)].Semi;
         if (SemiU < WInfo.Semi) WInfo.Semi = SemiU;
       }
@@ -998,7 +993,7 @@ struct SemiNCAInfo {
     SemiNCAInfo SNCA(BUI);
     SNCA.runDFS(ToIDom, 0, DescendBelow, 0);
     LLVM_DEBUG(dbgs() << "\tRunning Semi-NCA\n");
-    SNCA.runSemiNCA(DT, Level);
+    SNCA.runSemiNCA(DT);
     SNCA.reattachExistingSubtree(DT, PrevIDomSubTree);
   }
 
@@ -1122,7 +1117,7 @@ struct SemiNCAInfo {
                       << BlockNamePrinter(PrevIDom) << "\nRunning Semi-NCA\n");
 
     // Rebuild the remaining part of affected subtree.
-    SNCA.runSemiNCA(DT, MinLevel);
+    SNCA.runSemiNCA(DT);
     SNCA.reattachExistingSubtree(DT, PrevIDom);
   }
 



More information about the llvm-commits mailing list