[llvm] [FMV][GlobalOpt] Statically resolve calls to versioned functions. (PR #87939)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 6 14:00:19 PST 2025
================
@@ -2642,6 +2642,145 @@ DeleteDeadIFuncs(Module &M,
return Changed;
}
+// Follows the use-def chain of \p V backwards until it finds a Function,
+// in which case it collects in \p Versions.
+static void collectVersions(Value *V, SmallVectorImpl<Function *> &Versions) {
+ if (auto *F = dyn_cast<Function>(V)) {
+ Versions.push_back(F);
+ } else if (auto *Sel = dyn_cast<SelectInst>(V)) {
+ collectVersions(Sel->getTrueValue(), Versions);
+ collectVersions(Sel->getFalseValue(), Versions);
+ } else if (auto *Phi = dyn_cast<PHINode>(V)) {
+ for (unsigned I = 0, E = Phi->getNumIncomingValues(); I != E; ++I)
+ collectVersions(Phi->getIncomingValue(I), Versions);
+ }
----------------
goldsteinn wrote:
Err no I mean if there is a return value but you can't collect the assosiated function, couldn't we optimize to a static call when a better match existed? I.e im proposing adding:
```
...
} else if (auto *Phi = dyn_cast<PHINode>(V)) {
for (unsigned I = 0, E = Phi->getNumIncomingValues(); I != E; ++I)
if(!collectVersions(Phi->getIncomingValue(I), Versions)) return false;
return true;
}
else
return false;
```
then `if(!collectVersions(...)) { // skip transform entirely }`
https://github.com/llvm/llvm-project/pull/87939
More information about the llvm-commits
mailing list