[llvm] 575e68e - FunctionSpecialization: Make the ordering of BestSpecs stricter

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 05:02:37 PDT 2024


Author: Hans Wennborg
Date: 2024-06-12T14:02:18+02:00
New Revision: 575e68e571b4524d613e29d6a4f176cab8224bdd

URL: https://github.com/llvm/llvm-project/commit/575e68e571b4524d613e29d6a4f176cab8224bdd
DIFF: https://github.com/llvm/llvm-project/commit/575e68e571b4524d613e29d6a4f176cab8224bdd.diff

LOG: FunctionSpecialization: Make the ordering of BestSpecs stricter

otherwise it's not guaranteed which of two candidates with the same
score would get specialized first, or at all.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index a4c12006ee243..2d7b7355229ea 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -689,7 +689,9 @@ bool FunctionSpecializer::run() {
   // specialization budget, which is derived from maximum number of
   // specializations per specialization candidate function.
   auto CompareScore = [&AllSpecs](unsigned I, unsigned J) {
-    return AllSpecs[I].Score > AllSpecs[J].Score;
+    if (AllSpecs[I].Score != AllSpecs[J].Score)
+      return AllSpecs[I].Score > AllSpecs[J].Score;
+    return I > J;
   };
   const unsigned NSpecs =
       std::min(NumCandidates * MaxClones, unsigned(AllSpecs.size()));


        


More information about the llvm-commits mailing list