[llvm] 78a392c - [FuncSpec] Respect MaxConstantsThreshold

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 17 01:46:19 PST 2021


Author: Sjoerd Meijer
Date: 2021-12-17T09:25:45Z
New Revision: 78a392cf9f3420f36e4252535d2a6792e02703fa

URL: https://github.com/llvm/llvm-project/commit/78a392cf9f3420f36e4252535d2a6792e02703fa
DIFF: https://github.com/llvm/llvm-project/commit/78a392cf9f3420f36e4252535d2a6792e02703fa.diff

LOG: [FuncSpec] Respect MaxConstantsThreshold

This is a follow up of D115458 and truncates the worklist of actual arguments
that can be specialised to 'MaxConstantsThreshold' candidates if
MaxConstantsThreshold was exceeded. Thus, this changes the behaviour of option
-func-specialization-max-constants. Before it didn't specialise at all when
this threshold was exceeded, but now it specialises up to MaxConstantsThreshold
candidates from the sorted worklist.

Differential Revision: https://reviews.llvm.org/D115509

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
    llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index cb31f62fceca7..8b69f02da569a 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -409,11 +409,15 @@ class FunctionSpecializer {
         return L.Gain > R.Gain;
       });
 
-      // TODO: truncate the worklist to 'MaxConstantsThreshold' candidates if
+      // Truncate the worklist to 'MaxConstantsThreshold' candidates if
       // necessary.
       if (Worklist.size() > MaxConstantsThreshold) {
-        Worklist.clear();
-        continue;
+        LLVM_DEBUG(dbgs() << "FnSpecialization: number of constants exceed "
+                    << "the maximum number of constants threshold.\n"
+                    << "Truncating worklist to " << MaxConstantsThreshold
+                    << " candidates.\n");
+        Worklist.erase(Worklist.begin() + MaxConstantsThreshold,
+                       Worklist.end());
       }
 
       if (IsPartial || Worklist.size() < ActualConstArg.size())

diff  --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
index 9adb928dff3ba..4f43d14a15c9f 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
@@ -38,7 +38,7 @@ entry:
   ret i32 %add1
 }
 
-; CONST1-NOT: define internal i32 @foo.1(i32 %x, i32* %b, i32* %c)
+; CONST1:     define internal i32 @foo.1(i32 %x, i32* %b, i32* %c)
 ; CONST1-NOT: define internal i32 @foo.2(i32 %x, i32* %b, i32* %c)
 
 ; CHECK:        define internal i32 @foo.1(i32 %x, i32* %b, i32* %c) {


        


More information about the llvm-commits mailing list