[llvm] 342bbb7 - [FuncSpec] Don't specialise functions with NoDuplicate instructions.

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 01:02:23 PDT 2021


Author: Sjoerd Meijer
Date: 2021-06-21T09:02:11+01:00
New Revision: 342bbb7832b69cc2adba9acaac0ed2b9bffbe896

URL: https://github.com/llvm/llvm-project/commit/342bbb7832b69cc2adba9acaac0ed2b9bffbe896
DIFF: https://github.com/llvm/llvm-project/commit/342bbb7832b69cc2adba9acaac0ed2b9bffbe896.diff

LOG: [FuncSpec] Don't specialise functions with NoDuplicate instructions.

getSpecializationCost was returning INT_MAX for a case when specialisation
shouldn't happen, but this wasn't properly checked if specialisation was
forced.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index df289a62fa312..8c1a78a88ec5a 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -248,9 +248,12 @@ class FunctionSpecializer {
       Metrics.analyzeBasicBlock(&BB, (GetTTI)(*F), EphValues);
 
     // If the code metrics reveal that we shouldn't duplicate the function, we
-    // shouldn't specialize it. Set the specialization cost to the maximum.
-    if (Metrics.notDuplicatable)
-      return std::numeric_limits<unsigned>::max();
+    // shouldn't specialize it. Set the specialization cost to Invalid.
+    if (Metrics.notDuplicatable) {
+      InstructionCost C{};
+      C.setInvalid();
+      return C;
+    }
 
     // Otherwise, set the specialization cost to be the cost of all the
     // instructions in the function and penalty for specializing more functions.
@@ -417,6 +420,11 @@ class FunctionSpecializer {
     // function where the argument takes on the given constant value. If so,
     // add the constant to Constants.
     auto FnSpecCost = getSpecializationCost(F);
+    if (!FnSpecCost.isValid()) {
+      LLVM_DEBUG(dbgs() << "FnSpecialization: Invalid specialisation cost.\n");
+      return false;
+    }
+
     LLVM_DEBUG(dbgs() << "FnSpecialization: func specialisation cost: ";
                FnSpecCost.print(dbgs()); dbgs() << "\n");
 

diff  --git a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll
index f8c79d0704a4f..bb2d3a151d547 100644
--- a/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll
@@ -1,12 +1,12 @@
 ; RUN: opt -function-specialization -force-function-specialization -S < %s | FileCheck %s
 
-; FIXME: Function foo gets specialised even though it contains an instrinsic
+; Check that function foo does not gets specialised as it contains an instrinsic
 ; that is marked as NoDuplicate.
 ; Please note that the use of the hardwareloop intrinsic is arbitrary; it's
 ; just an easy to use intrinsic that has NoDuplicate.
 
-; CHECK: @foo.1(
-; CHECK: @foo.2(
+; CHECK-NOT: @foo.1(
+; CHECK-NOT: @foo.2(
 
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 


        


More information about the llvm-commits mailing list