[llvm] ff75121 - [LoopInfo] Avoid redundant DomTree lookup (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 03:03:32 PST 2023


Author: Nikita Popov
Date: 2023-11-21T12:03:21+01:00
New Revision: ff75121d4b6c5f4023e36a4edd7296a419ed5c04

URL: https://github.com/llvm/llvm-project/commit/ff75121d4b6c5f4023e36a4edd7296a419ed5c04
DIFF: https://github.com/llvm/llvm-project/commit/ff75121d4b6c5f4023e36a4edd7296a419ed5c04.diff

LOG: [LoopInfo] Avoid redundant DomTree lookup (NFC)

For Header we already have the DomTreeNode. For Backedge, fetch it
only once.

Added: 
    

Modified: 
    llvm/include/llvm/Support/GenericLoopInfoImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/GenericLoopInfoImpl.h b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
index 85233d38f0f6db9..15af9cd794e2b2a 100644
--- a/llvm/include/llvm/Support/GenericLoopInfoImpl.h
+++ b/llvm/include/llvm/Support/GenericLoopInfoImpl.h
@@ -581,10 +581,9 @@ void LoopInfoBase<BlockT, LoopT>::analyze(const DomTreeBase<BlockT> &DomTree) {
     // Check each predecessor of the potential loop header.
     for (const auto Backedge : children<Inverse<BlockT *>>(Header)) {
       // If Header dominates predBB, this is a new loop. Collect the backedges.
-      if (DomTree.dominates(Header, Backedge) &&
-          DomTree.isReachableFromEntry(Backedge)) {
+      const DomTreeNodeBase<BlockT> *BackedgeNode = DomTree.getNode(Backedge);
+      if (BackedgeNode && DomTree.dominates(DomNode, BackedgeNode))
         Backedges.push_back(Backedge);
-      }
     }
     // Perform a backward CFG traversal to discover and map blocks in this loop.
     if (!Backedges.empty()) {


        


More information about the llvm-commits mailing list