@@ -740,10 +740,19 @@ bool FunctionSpecializer::runOneSpec(Spec &S, bool Chained, SpecMap &SM,
740740 // If the code metrics reveal that we shouldn't duplicate the function,
741741 // or if the code size implies that this function is easy to get inlined,
742742 // then we shouldn't specialize it.
743- if (Metrics.notDuplicatable || !Metrics.NumInsts .isValid () ||
744- (RequireMinSize && Metrics.NumInsts < MinFunctionSize))
743+ if (Metrics.notDuplicatable || !Metrics.NumInsts .isValid ())
745744 return false ;
746745
746+ if (RequireMinSize && Metrics.NumInsts < MinFunctionSize) {
747+ if (Chained) {
748+ // Want to specialize as part of chain still so we can more accurately
749+ // assess the chain specialization
750+ S.SpecializeOnOwn = false ;
751+ } else {
752+ return false ;
753+ }
754+ }
755+
747756 // When specialization on literal constants is disabled, only consider
748757 // recursive functions when running multiple times to save wasted analysis,
749758 // as we will not be able to specialize on any newly found literal constant
@@ -800,7 +809,7 @@ bool FunctionSpecializer::run() {
800809
801810 unsigned IndepSpecs = 0 ;
802811 for (auto &S : AllSpecs)
803- if (!S.AllChains )
812+ if (S. SpecializeOnOwn && !S.AllChains )
804813 ++IndepSpecs;
805814 if (!NumCandidates || !IndepSpecs) {
806815 LLVM_DEBUG (
@@ -813,9 +822,9 @@ bool FunctionSpecializer::run() {
813822 // specialization budget, which is derived from maximum number of
814823 // specializations per specialization candidate function.
815824 auto CompareScore = [&AllSpecs](unsigned I, unsigned J) {
816- if (AllSpecs[J].AllChains )
825+ if (!AllSpecs[J]. SpecializeOnOwn || AllSpecs[J].AllChains )
817826 return true ;
818- if (AllSpecs[I].AllChains )
827+ if (!AllSpecs[I]. SpecializeOnOwn || AllSpecs[I].AllChains )
819828 return false ;
820829 if (AllSpecs[I].Score != AllSpecs[J].Score )
821830 return AllSpecs[I].Score > AllSpecs[J].Score ;
0 commit comments