Skip to content

[IPO] Avoid repeated hash lookups (NFC) #131720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/131720.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/ArgumentPromotion.cpp (+4-4)
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index 2a3df722d29c5..78115674f3cef 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -236,13 +236,13 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
     ArgNo = 0;
     for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
          ++I, ++AI, ++ArgNo) {
-      if (!ArgsToPromote.count(&*I)) {
+      auto ArgIt = ArgsToPromote.find(&*I);
+      if (ArgIt == ArgsToPromote.end()) {
         Args.push_back(*AI); // Unmodified argument
         ArgAttrVec.push_back(CallPAL.getParamAttrs(ArgNo));
       } else if (!I->use_empty()) {
         Value *V = *AI;
-        const auto &ArgParts = ArgsToPromote.find(&*I)->second;
-        for (const auto &Pair : ArgParts) {
+        for (const auto &Pair : ArgIt->second) {
           LoadInst *LI = IRB.CreateAlignedLoad(
               Pair.second.Ty,
               createByteGEP(IRB, DL, V, Pair.second.Ty, Pair.first),
@@ -266,7 +266,7 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
           ArgAttrVec.push_back(AttributeSet());
         }
       } else {
-        assert(ArgsToPromote.count(&*I) && I->use_empty());
+        assert(ArgIt != ArgsToPromote.end() && I->use_empty());
         DeadArgs.emplace_back(AI->get());
       }
     }

@kazutakahirata
Copy link
Contributor Author

@shiltian Friendly ping. Thanks!

@kazutakahirata
Copy link
Contributor Author

Thanks @shiltian!

@kazutakahirata kazutakahirata merged commit 6313550 into llvm:main Mar 18, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_IPO branch March 18, 2025 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants