[llvm] [ThinLTO] Do not duplicate import a function that is actually defined in the current module (PR #110064)

William Junda Huang via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 3 21:20:15 PDT 2024


================
@@ -595,11 +595,15 @@ Value *IRLinker::materialize(Value *V, bool ForIndirectSymbol) {
   if (!SGV)
     return nullptr;
 
+  // If SGV is from dest, it is already materialized when dest was loaded.
+  if (SGV->getParent() == &DstM)
+    return nullptr;
+
   // When linking a global from other modules than source & dest, skip
   // materializing it because it would be mapped later when its containing
   // module is linked. Linking it now would potentially pull in many types that
   // may not be mapped properly.
-  if (SGV->getParent() != &DstM && SGV->getParent() != SrcM.get())
+  if (SGV->getParent() != SrcM.get())
----------------
huangjd wrote:

I added an assert and there's only one test case hitting it. It turns out to be a similar situation but that case does not involve mapping function pointer in metadata so either mapping the global value or not does not affect the correctness.

https://github.com/llvm/llvm-project/pull/110064


More information about the llvm-commits mailing list