@@ -95,6 +95,21 @@ STATISTIC(NumIFuncsDeleted, "Number of IFuncs removed");
95
95
STATISTIC (NumGlobalArraysPadded,
96
96
" Number of global arrays padded to alignment boundary" );
97
97
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
+
98
113
static cl::opt<bool >
99
114
EnableColdCCStressTest (" enable-coldcc-stress-test" ,
100
115
cl::desc (" Enable stress test of coldcc by adding "
@@ -2715,6 +2730,9 @@ static bool OptimizeNonTrivialIFuncs(
2715
2730
2716
2731
assert (!Callees.empty () && " Expecting successful collection of versions" );
2717
2732
2733
+ LLVM_DEBUG (dbgs () << " Statically resolving calls to function "
2734
+ << Resolver->getName () << " \n " );
2735
+
2718
2736
// Cache the feature mask for each callee.
2719
2737
for (Function *Callee : Callees) {
2720
2738
auto [It, Inserted] = FeatureMask.try_emplace (Callee);
@@ -2785,20 +2803,15 @@ static bool OptimizeNonTrivialIFuncs(
2785
2803
} else {
2786
2804
// We can't reason much about non-FMV callers. Just pick the highest
2787
2805
// 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 ;
2798
2808
}
2799
2809
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 " );
2801
2813
CS->setCalledOperand (Callee);
2814
+ }
2802
2815
Changed = true ;
2803
2816
}
2804
2817
if (IF.use_empty () ||
0 commit comments