@@ -95,6 +95,21 @@ STATISTIC(NumIFuncsDeleted, "Number of IFuncs removed");
9595STATISTIC (NumGlobalArraysPadded,
9696 " Number of global arrays padded to alignment boundary" );
9797
98+ // FIXME:
99+ // Optimizing non-FMV callers is causing a regression in the llvm test suite,
100+ // specifically a 'predres' version is unexpectedly trapping on GravitonG4.
101+ // My explanation is that when the caller in not a versioned function, the
102+ // compiler exclusively relies on the command line option, or target attribute
103+ // to deduce whether a feature is available. However, there is no guarantee
104+ // that in reality the host supports those implied features, which arguably
105+ // is a user error. This option allows disabling the optimization as a short
106+ // term workaround to keep the bots green.
107+ static cl::opt<bool >
108+ OptimizeNonFMVCallers (" optimize-non-fmv-callers" ,
109+ cl::desc (" Statically resolve calls to versioned "
110+ " functions from non-versioned callers." ),
111+ cl::init(false ), cl::Hidden);
112+
98113static cl::opt<bool >
99114 EnableColdCCStressTest (" enable-coldcc-stress-test" ,
100115 cl::desc (" Enable stress test of coldcc by adding "
@@ -2715,6 +2730,9 @@ static bool OptimizeNonTrivialIFuncs(
27152730
27162731 assert (!Callees.empty () && " Expecting successful collection of versions" );
27172732
2733+ LLVM_DEBUG (dbgs () << " Statically resolving calls to function "
2734+ << Resolver->getName () << " \n " );
2735+
27182736 // Cache the feature mask for each callee.
27192737 for (Function *Callee : Callees) {
27202738 auto [It, Inserted] = FeatureMask.try_emplace (Callee);
@@ -2785,20 +2803,15 @@ static bool OptimizeNonTrivialIFuncs(
27852803 } else {
27862804 // We can't reason much about non-FMV callers. Just pick the highest
27872805 // priority callee if it matches, otherwise bail.
2788- // if (I > 0 || !implies(CallerBits, CalleeBits))
2789- //
2790- // FIXME: This is causing a regression in the llvm test suite,
2791- // specifically a 'predres' version is unexpectedly trapping on
2792- // GravitonG4. My explanation is that when the caller in not a
2793- // versioned function, the compiler exclusively relies on the
2794- // command line option, or target attribute to deduce whether a
2795- // feature is available. However, there is no guarantee that in
2796- // reality the host supports those implied features.
2797- continue ;
2806+ if (!OptimizeNonFMVCallers || I > 0 || !implies (CallerBits, CalleeBits))
2807+ continue ;
27982808 }
27992809 auto &Calls = CallSites[Caller];
2800- for (CallBase *CS : Calls)
2810+ for (CallBase *CS : Calls) {
2811+ LLVM_DEBUG (dbgs () << " Redirecting call " << Caller->getName () << " -> "
2812+ << Callee->getName () << " \n " );
28012813 CS->setCalledOperand (Callee);
2814+ }
28022815 Changed = true ;
28032816 }
28042817 if (IF.use_empty () ||
0 commit comments