From 23f992ca572d46fa208003818b01beff5bd20ada Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 23 Oct 2025 10:54:27 -0700 Subject: [PATCH 1/2] [ThinLTO] Simplify checking for single external copy (NFCI) Replace a loop over all summary copies with a simple check for a single externally available copy of a symbol. The usage of this result has changed since it was added and we now only need to know if there is a single one. --- llvm/lib/LTO/LTO.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 9d0fa116c85bf..7e4436a47f70d 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -471,16 +471,14 @@ static void thinLTOInternalizeAndPromoteGUID( ValueInfo VI, function_ref isExported, function_ref isPrevailing) { - auto ExternallyVisibleCopies = - llvm::count_if(VI.getSummaryList(), - [](const std::unique_ptr &Summary) { - return !GlobalValue::isLocalLinkage(Summary->linkage()); - }); - // Before performing index-based internalization and promotion for this GUID, // the local flag should be consistent with the summary list linkage types. VI.verifyLocal(); + bool SingleExternallyVisibleCopy = + VI.getSummaryList().size() == 1 && + !GlobalValue::isLocalLinkage(VI.getSummaryList().front()->linkage()); + for (auto &S : VI.getSummaryList()) { // First see if we need to promote an internal value because it is not // exported. @@ -543,7 +541,9 @@ static void thinLTOInternalizeAndPromoteGUID( GlobalValue::isExternalWeakLinkage(S->linkage())) continue; - if (isPrevailing(VI.getGUID(), S.get()) && ExternallyVisibleCopies == 1) + // We may have a single summary copy that is externally visible but not + // prevailing if the prevailing copy is in a native object. + if (SingleExternallyVisibleCopy && isPrevailing(VI.getGUID(), S.get())) S->setLinkage(GlobalValue::InternalLinkage); } } From 4f17ea7cd0c4a871e7beab056c7408b937d72a09 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 23 Oct 2025 19:45:53 -0700 Subject: [PATCH 2/2] Address comments --- llvm/lib/LTO/LTO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 7e4436a47f70d..c2eb26bc8d03f 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -475,7 +475,7 @@ static void thinLTOInternalizeAndPromoteGUID( // the local flag should be consistent with the summary list linkage types. VI.verifyLocal(); - bool SingleExternallyVisibleCopy = + const bool SingleExternallyVisibleCopy = VI.getSummaryList().size() == 1 && !GlobalValue::isLocalLinkage(VI.getSummaryList().front()->linkage());