Index: lib/CodeGen/MachineBlockPlacement.cpp =================================================================== --- lib/CodeGen/MachineBlockPlacement.cpp +++ lib/CodeGen/MachineBlockPlacement.cpp @@ -453,8 +453,11 @@ // If we outline optional branches, look whether Succ is unavoidable, i.e. // dominates all terminators of the MachineFunction. If it does, other // successors must be optional. Don't do this for cold branches. + // Also, return branches seem to behave perversely as well. Don't outline in + // favor of them either, unless the exit branch is hot. if (OutlineOptionalBranches && SuccProb > HotProb.getCompl() && - UnavoidableBlocks.count(Succ) > 0) { + UnavoidableBlocks.count(Succ) > 0 && + (!Succ->isReturnBlock() || SuccProb > HotProb)) { auto HasShortOptionalBranch = [&]() { for (MachineBasicBlock *Pred : Succ->predecessors()) { // Check whether there is an unplaced optional branch. @@ -672,7 +675,7 @@ // after this block. MachineBasicBlock *BestSucc = selectBestSuccessor(BB, Chain, BlockFilter); - // If an immediate successor isn't available, look for the best viable + // If an immediate successor isn't available, look for the best viable // block among those we've identified as not violating the loop's CFG at // this point. This won't be a fallthrough, but it will increase locality. if (!BestSucc)