[llvm] [MergeFuncs] Don't introduce calls to {linkonce,weak}_odr functions. (PR #125050)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 13:27:47 PST 2025


================
@@ -891,8 +891,10 @@ bool MergeFunctions::writeThunkOrAlias(Function *F, Function *G) {
 
 // Merge two equivalent functions. Upon completion, Function G is deleted.
 void MergeFunctions::mergeTwoFunctions(Function *F, Function *G) {
-  if (F->isInterposable()) {
-    assert(G->isInterposable());
+  if (F->isInterposable() || G->hasWeakODRLinkage() ||
----------------
fhahn wrote:

The check here is to decide whether we cannot use `F` instead of `G`. If the condition is true, we don't use `F` for `G` but introduce new function with the implementation of `F` that is called by both `F` and `G`.

If the condition is false, we update all callers of `G` to use `F` and update `G` to call `F`.

As @cachemeifyoucan the issue occurs without (Thin)LTO.


Unfortunately `linkonce_odr` & `weak_odr` aren't considered interposable  (https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/GlobalValue.h#L426). `linkonce_odr` and `weak_odr` functions are guaranteed to be replaced by something semantically equivalent, but they could have different semantically equivalent implementations in modules, where merging can be done in one module but not the other.

I tried to provide a more detailed example here: https://github.com/llvm/llvm-project/pull/125050#issuecomment-2627799384



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


More information about the llvm-commits mailing list