diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp --- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -409,11 +409,15 @@ 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 --- a/llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll +++ b/llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll @@ -38,7 +38,7 @@ 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) {