Index: llvm/lib/Analysis/InlineCost.cpp =================================================================== --- llvm/lib/Analysis/InlineCost.cpp +++ llvm/lib/Analysis/InlineCost.cpp @@ -1580,6 +1580,8 @@ InlineResult CallAnalyzer::analyzeBlock(BasicBlock *BB, SmallPtrSetImpl &EphValues) { + InlineResult Result = true; + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { // FIXME: Currently, the number of instructions in a function regardless of // our ability to simplify them during inline to constants or dead code, @@ -1633,7 +1635,7 @@ << NV("InlineResult", IR.message) << ") and cost is not fully computed"; }); - return IR; + return !Result ? Result : IR; } // If the caller is a recursive function then we don't want to inline @@ -1649,16 +1651,19 @@ << NV("Callee", &F) << " is " << NV("InlineResult", IR.message) << ". Cost is not fully computed"; }); - return IR; + return !Result ? Result : IR; } // Check if we've passed the maximum possible threshold so we don't spin in // huge basic blocks that will never inline. - if (Cost >= Threshold && !ComputeFullInlineCost) - return false; + if (Cost >= Threshold) { + if (!ComputeFullInlineCost) + return false; + Result = false; + } } - return true; + return Result; } /// Compute the base pointer and cumulative constant offsets for V. @@ -1785,12 +1790,17 @@ if (F.getCallingConv() == CallingConv::Cold) Cost += InlineConstants::ColdccPenalty; + InlineResult Result = true; + // Check if we're done. This can happen due to bonuses and penalties. - if (Cost >= Threshold && !ComputeFullInlineCost) - return "high cost"; + if (Cost >= Threshold) { + Result = "high cost"; + if (!ComputeFullInlineCost) + return Result; + } if (F.empty()) - return true; + return !Result ? Result : InlineResult(true); Function *Caller = Call.getFunction(); // Check if the caller function is recursive itself. @@ -1849,8 +1859,11 @@ for (unsigned Idx = 0; Idx != BBWorklist.size(); ++Idx) { // 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 && !ComputeFullInlineCost) - break; + if (Cost >= Threshold) { + Result = !Result ? Result : InlineResult(false); + if (!ComputeFullInlineCost) + break; + } BasicBlock *BB = BBWorklist[Idx]; if (BB->empty()) @@ -1867,13 +1880,13 @@ if (BB->hasAddressTaken()) for (User *U : BlockAddress::get(&*BB)->users()) if (!isa(*U)) - return "blockaddress used outside of callbr"; + return !Result ? Result : "blockaddress used outside of callbr"; // Analyze the cost of this block. If we blow through the threshold, this // returns false, and we can bail on out. InlineResult IR = analyzeBlock(BB, EphValues); if (!IR) - return IR; + return !Result ? Result : IR; Instruction *TI = BB->getTerminator(); @@ -1926,7 +1939,7 @@ // inlining this would cause the removal of the caller (so the instruction // is not actually duplicated, just moved). if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall) - return "noduplicate"; + return !Result ? Result : "noduplicate"; // Loops generally act a lot like calls in that they act like barriers to // movement, require a certain amount of setup, etc. So when optimising for @@ -1954,7 +1967,7 @@ else if (NumVectorInstructions <= NumInstructions / 2) Threshold -= VectorBonus/2; - return Cost < std::max(1, Threshold); + return !Result ? Result : InlineResult(Cost < std::max(1, Threshold)); } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)