Skip to content

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Oct 18, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/GlobalDCE.cpp (+4-9)
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index eca36fb31cea0e..9a7447797e723a 100644
--- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -67,16 +67,11 @@ void GlobalDCEPass::ComputeDependencies(Value *V,
     Deps.insert(GV);
   } else if (auto *CE = dyn_cast<Constant>(V)) {
     // Avoid walking the whole tree of a big ConstantExprs multiple times.
-    auto Where = ConstantDependenciesCache.find(CE);
-    if (Where != ConstantDependenciesCache.end()) {
-      auto const &K = Where->second;
-      Deps.insert(K.begin(), K.end());
-    } else {
-      SmallPtrSetImpl<GlobalValue *> &LocalDeps = ConstantDependenciesCache[CE];
+    auto [It, Inserted] = ConstantDependenciesCache.try_emplace(CE);
+    if (Inserted)
       for (User *CEUser : CE->users())
-        ComputeDependencies(CEUser, LocalDeps);
-      Deps.insert(LocalDeps.begin(), LocalDeps.end());
-    }
+        ComputeDependencies(CEUser, It->second);
+    Deps.insert(It->second.begin(), It->second.end());
   }
 }
 

ComputeDependencies(CEUser, LocalDeps);
Deps.insert(LocalDeps.begin(), LocalDeps.end());
}
ComputeDependencies(CEUser, It->second);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is safe. The recursive ComputeDependencies call may also modify ConstantDependenciesCache, invalidating It.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Thank you for catching this!

@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_IPO branch October 18, 2024 15:32
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