Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp =================================================================== --- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -406,11 +406,15 @@ llvm::sort(Worklist, [] (ArgInfo &L, ArgInfo &R) { 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()) Index: llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll =================================================================== --- llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll +++ 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) {