[llvm] 6778dbe - [DomTree] Avoid duplicate hash lookup (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 27 06:05:10 PST 2023


Author: Nikita Popov
Date: 2023-11-27T15:05:03+01:00
New Revision: 6778dbe50228ea47c586d7b9b60ef57a78915148

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

LOG: [DomTree] Avoid duplicate hash lookup (NFC)

We're performing the same lookup twice here, just to access
different fields. Only perform it once.

Also prefer using find() over operator[], as we do not want to
perform an insert if the node does not exist.

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 97529cd3277f30b..779418feff44c14 100644
--- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -304,8 +304,12 @@ struct SemiNCAInfo {
       auto &WInfo = *NumToInfo[i];
       const unsigned SDomNum = NodeToInfo[NumToNode[WInfo.Semi]].DFSNum;
       NodePtr WIDomCandidate = WInfo.IDom;
-      while (NodeToInfo[WIDomCandidate].DFSNum > SDomNum)
-        WIDomCandidate = NodeToInfo[WIDomCandidate].IDom;
+      while (true) {
+        auto &WIDomCandidateInfo = NodeToInfo.find(WIDomCandidate)->second;
+        if (WIDomCandidateInfo.DFSNum <= SDomNum)
+          break;
+        WIDomCandidate = WIDomCandidateInfo.IDom;
+      }
 
       WInfo.IDom = WIDomCandidate;
     }


        


More information about the llvm-commits mailing list