[llvm] [AsmPrinter] Always emit global equivalents if there is non-global uses (PR #145648)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 01:09:55 PDT 2025


================
@@ -2209,9 +2219,9 @@ void AsmPrinter::emitGlobalGOTEquivs() {
 
   SmallVector<const GlobalVariable *, 8> FailedCandidates;
   for (auto &I : GlobalGOTEquivs) {
-    const GlobalVariable *GV = I.second.first;
-    unsigned Cnt = I.second.second;
-    if (Cnt)
+    const GlobalVariable *GV = I.second.GV;
+    unsigned Cnt = I.second.NumUses;
+    if (Cnt > 0 && !I.second.HasNonGlobalUsers)
----------------
dianqk wrote:

Here is to prevent duplicate emissions.
For `HasNonGlobalUsers` case,  `emitGlobalVariable` has emitted them before `emitGlobalGOTEquivs`:

```
    // Skip the emission of global equivalents if they are only used by global
    // values. The symbol can be emitted later on by emitGlobalGOTEquivs in case
    // it turns out to be needed.
    if (GlobalGOTEquivs.contains(getSymbol(GV)) &&
        !GlobalGOTEquivs[getSymbol(GV)].HasNonGlobalUsers)
      return;
```

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


More information about the llvm-commits mailing list