[llvm] [FMV][GlobalOpt] Statically resolve calls to versioned functions. (PR #87939)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 12:49:17 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:

If you fail to walk use-def chain and find the actual function, could it not be an issue in that we might be ignorant to the actual best match?

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


More information about the llvm-commits mailing list