Skip to content

Commit 342bbb7

Browse files
author
Sjoerd Meijer
committed
[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
1 parent 225b960 commit 342bbb7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,12 @@ class FunctionSpecializer {
248248
Metrics.analyzeBasicBlock(&BB, (GetTTI)(*F), EphValues);
249249

250250
// If the code metrics reveal that we shouldn't duplicate the function, we
251-
// shouldn't specialize it. Set the specialization cost to the maximum.
252-
if (Metrics.notDuplicatable)
253-
return std::numeric_limits<unsigned>::max();
251+
// shouldn't specialize it. Set the specialization cost to Invalid.
252+
if (Metrics.notDuplicatable) {
253+
InstructionCost C{};
254+
C.setInvalid();
255+
return C;
256+
}
254257

255258
// Otherwise, set the specialization cost to be the cost of all the
256259
// instructions in the function and penalty for specializing more functions.
@@ -417,6 +420,11 @@ class FunctionSpecializer {
417420
// function where the argument takes on the given constant value. If so,
418421
// add the constant to Constants.
419422
auto FnSpecCost = getSpecializationCost(F);
423+
if (!FnSpecCost.isValid()) {
424+
LLVM_DEBUG(dbgs() << "FnSpecialization: Invalid specialisation cost.\n");
425+
return false;
426+
}
427+
420428
LLVM_DEBUG(dbgs() << "FnSpecialization: func specialisation cost: ";
421429
FnSpecCost.print(dbgs()); dbgs() << "\n");
422430

llvm/test/Transforms/FunctionSpecialization/function-specialization-nodup2.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
; RUN: opt -function-specialization -force-function-specialization -S < %s | FileCheck %s
22

3-
; FIXME: Function foo gets specialised even though it contains an instrinsic
3+
; Check that function foo does not gets specialised as it contains an instrinsic
44
; that is marked as NoDuplicate.
55
; Please note that the use of the hardwareloop intrinsic is arbitrary; it's
66
; just an easy to use intrinsic that has NoDuplicate.
77

8-
; CHECK: @foo.1(
9-
; CHECK: @foo.2(
8+
; CHECK-NOT: @foo.1(
9+
; CHECK-NOT: @foo.2(
1010

1111
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
1212

0 commit comments

Comments
 (0)