diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index 5be6baf64c209a3b7c9903c2bd20008b6f3e77a5..befcd0022196b80485688a01afe12d68d9698619 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -472,6 +472,20 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { ++NumBranchOpts; return OptimizeBlock(MBB); } + + // If the prior block branches here on true and somewhere else on false, and + // if the branch condition is reversible, reverse the branch to create a + // fall-through. + if (PriorTBB == &*MBB) { + std::vector NewPriorCond(PriorCond); + if (!TII->ReverseBranchCondition(NewPriorCond)) { + TII->RemoveBranch(PrevBB); + TII->InsertBranch(PrevBB, PriorFBB, 0, NewPriorCond); + MadeChange = true; + ++NumBranchOpts; + return OptimizeBlock(MBB); + } + } } // Analyze the branch in the current block.