[llvm] [GlobalOpt][FMV] Fix static resolution of calls. (PR #160011)
Momchil Velikov via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 6 03:57:18 PST 2025
================
@@ -2510,31 +2511,37 @@ static bool collectVersions(TargetTransformInfo &TTI, Value *V,
return true;
}
-// Bypass the IFunc Resolver of MultiVersioned functions when possible. To
-// deduce whether the optimization is legal we need to compare the target
-// features between caller and callee versions. The criteria for bypassing
-// the resolver are the following:
-//
-// * If the callee's feature set is a subset of the caller's feature set,
-// then the callee is a candidate for direct call.
-//
-// * Among such candidates the one of highest priority is the best match
-// and it shall be picked, unless there is a version of the callee with
-// higher priority than the best match which cannot be picked from a
-// higher priority caller (directly or through the resolver).
-//
-// * For every higher priority callee version than the best match, there
-// is a higher priority caller version whose feature set availability
-// is implied by the callee's feature set.
+// Try to statically resolve calls to versioned functions when possible. First
+// we identify the function versions which are associated with an IFUNC symbol.
+// We do that by examining the resolver function of the IFUNC. Once we have
+// collected all the function versions, we sort them in decreasing priority
+// order. This is necessary for identifying the highest priority callee version
+// for a given caller version. We then collect all the callsites to versioned
+// functions. The static resolution is performed by comparing the feature sets
+// between callers and callees. Versions of the callee may be skipped if they
+// depend on features we already know are unavailable. This information can
----------------
momchil-velikov wrote:
> Versions of the callee may be skipped if they
IMHO this comment is better placed a bit further down around line 2682.
Or provide a more complete overview of the algorithm here, something like:
> * Start a walk over caller and callee lists simultaneously in order of decreasing priority
> * Statically resolve calls from the current caller to the current callee, iff the caller feature bits are a superset of the callee feature bits.
> * For non-FMV callers, as long as the caller feature bits are a subset of the callee feature bits, advance to the next callee. This effectively prevents considering the current callee as a candidate for static resolution by following callers, because `<insert justification here>`.
> * Advance to the next caller.
https://github.com/llvm/llvm-project/pull/160011
More information about the llvm-commits
mailing list