Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -1307,7 +1307,7 @@ // Bail out the moment we cross the threshold. This means we'll under-count // the cost, but only when undercounting doesn't matter. if (Cost > Threshold) - break; + return false; BasicBlock *BB = BBWorklist[Idx]; if (BB->empty()) @@ -1373,7 +1373,7 @@ // inlining. if (SingleBB && TI->getNumSuccessors() > 1) { // Take off the bonus we applied to the threshold. - Threshold -= SingleBBBonus; + Threshold = std::max(Threshold - SingleBBBonus, 0); SingleBB = false; } } @@ -1388,10 +1388,12 @@ // subtract the excess bonus, if any, from the Threshold before // comparing against Cost. if (NumVectorInstructions <= NumInstructions / 10) - Threshold -= FiftyPercentVectorBonus; + Threshold = std::max(Threshold - FiftyPercentVectorBonus, 0); else if (NumVectorInstructions <= NumInstructions / 2) - Threshold -= (FiftyPercentVectorBonus - TenPercentVectorBonus); + Threshold = std::max( + Threshold - (FiftyPercentVectorBonus - TenPercentVectorBonus), 0); + assert(Threshold >= 0 && "Inlinining threshold must be non-negative"); return Cost < std::max(1, Threshold); } Index: test/Transforms/Inline/inline_unreachable-2.ll =================================================================== --- /dev/null +++ test/Transforms/Inline/inline_unreachable-2.ll @@ -0,0 +1,19 @@ +; RUN: opt < %s -inline -S | FileCheck %s + +; CHECK-LABEL: caller +; CHECK: call void @callee +define void @caller(i32 %a, i1 %b) #0 { + call void @callee(i32 %a, i1 %b) + unreachable +} + +define void @callee(i32 %a, i1 %b) { + call void asm sideeffect "", ""() + br i1 %b, label %bb1, label %bb2 +bb1: + call void asm sideeffect "", ""() + ret void +bb2: + call void asm sideeffect "", ""() + ret void +}