diff options
author | Alexandros Lamprineas <alexandros.lamprineas@arm.com> | 2024-06-21 09:33:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-21 09:33:41 +0100 |
commit | 7c946f04cf363a8c581529907be8ee9f735591c7 (patch) | |
tree | 1244e5f7e80a344c432ace24496ce5e1f907948d /llvm/lib/Transforms | |
parent | c6a257fe0fc9ba677d96929a34dedc5f243aad7d (diff) | |
download | llvm-7c946f04cf363a8c581529907be8ee9f735591c7.zip llvm-7c946f04cf363a8c581529907be8ee9f735591c7.tar.gz llvm-7c946f04cf363a8c581529907be8ee9f735591c7.tar.bz2 |
[GlobalOpt] Don't resolve aliased ifuncs with undefined resolvees. (#96220)
Fixes https://github.com/llvm/llvm-project/issues/96197.
A global alias should always point to a definition. Ifuncs are
definitions, so far so good. However an ifunc may be statically resolved
to a function that is declared but not defined in the translation unit.
With this patch we perform static resolution if:
* the resolvee is defined, else if
* none of the ifunc users is a global alias
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index b7c6d25..411a845 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -2458,7 +2458,9 @@ static bool OptimizeStaticIFuncs(Module &M) { bool Changed = false; for (GlobalIFunc &IF : M.ifuncs()) if (Function *Callee = hasSideeffectFreeStaticResolution(IF)) - if (!IF.use_empty()) { + if (!IF.use_empty() && + (!Callee->isDeclaration() || + none_of(IF.users(), [](User *U) { return isa<GlobalAlias>(U); }))) { IF.replaceAllUsesWith(Callee); NumIFuncsResolved++; Changed = true; |