Skip to content

Commit

Permalink
[FuncSpec] Respect MaxConstantsThreshold
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Sjoerd Meijer committed Dec 17, 2021
1 parent 6bd8f11 commit 78a392c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
Expand Up @@ -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())
Expand Down
Expand Up @@ -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) {
Expand Down

0 comments on commit 78a392c

Please sign in to comment.