[llvm] [MergeFunctions] keep the symbol of a function an alias points at on COFF (PR #222024)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 13:47:12 PDT 2026


================
@@ -910,30 +955,27 @@ static void mergeEntryCountsAndImportsInto(Function &F, Function &G) {
   F.setEntryCount(Sum, AllImports.empty() ? nullptr : &AllImports);
 }
 
-bool MergeFunctions::writeThunkOrAliasIfNeeded(Function *F, Function *G) {
-  bool ShouldErase =
-      G->isDiscardableIfUnused() && G->use_empty() && !MergeFunctionsPDI;
-  bool ShouldAlias = canCreateAliasFor(G);
-  bool ShouldThunk = canCreateThunkFor(F);
-
-  if (!ShouldErase && !ShouldAlias && !ShouldThunk)
+bool MergeFunctions::eraseIfUnused(Function *G) {
+  if (!G->isDiscardableIfUnused() || !G->use_empty() || MergeFunctionsPDI)
     return false;
+  G->eraseFromParent();
+  return true;
+}
 
-  if (ShouldErase) {
-    G->eraseFromParent();
-    return true;
-  }
-
-  if (ShouldAlias) {
-    writeAlias(F, G);
-    return true;
-  }
-  if (ShouldThunk) {
-    writeThunk(F, G);
-    return true;
-  }
+bool MergeFunctions::createAlias(Function *F, Function *G) {
+  if (!canCreateAliasFor(G))
----------------
compnerd wrote:

I'm now wondering if we need all this complexity? Can we not simplify this to:

```
if (T->supportsWeakAlias())
  return weakAlias(F, G);
F->getParent()->RAUW(F, G);
```

That is, unless the address is significant, we can simply RAUW. If the address _is_ significant, we couldn't've used the alias in any case, and we must thunk (i.e. `f: jmp g`).

I feel like that should really simplify the handling here. What am I missing?

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


More information about the llvm-commits mailing list