Index: include/llvm/CodeGen/MachineBasicBlock.h =================================================================== --- include/llvm/CodeGen/MachineBasicBlock.h +++ include/llvm/CodeGen/MachineBasicBlock.h @@ -367,8 +367,8 @@ /// Update the terminator instructions in block to account for changes to the /// layout. If the block previously used a fallthrough, it may now need a /// branch, and if it previously used branching it may now be able to use a - /// fallthrough. - void updateTerminator(); + /// fallthrough. Return true if the terminator is updated, otherwise false. + bool updateTerminator(); // Machine-CFG mutators Index: lib/CodeGen/MachineBasicBlock.cpp =================================================================== --- lib/CodeGen/MachineBasicBlock.cpp +++ lib/CodeGen/MachineBasicBlock.cpp @@ -400,10 +400,10 @@ getParent()->splice(++NewBefore->getIterator(), getIterator()); } -void MachineBasicBlock::updateTerminator() { +bool MachineBasicBlock::updateTerminator() { const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo(); // A block with no successors has no concerns with fall-through edges. - if (this->succ_empty()) return; + if (this->succ_empty()) return false; MachineBasicBlock *TBB = nullptr, *FBB = nullptr; SmallVector Cond; @@ -415,8 +415,10 @@ if (TBB) { // The block has an unconditional branch. If its successor is now // its layout successor, delete the branch. - if (isLayoutSuccessor(TBB)) + if (isLayoutSuccessor(TBB)) { TII->RemoveBranch(*this); + return true; + } } else { // The block has an unconditional fallthrough. If its successor is not // its layout successor, insert a branch. First we have to locate the @@ -431,12 +433,14 @@ // If there is no non-landing-pad successor, the block has no // fall-through edges to be concerned with. if (!TBB) - return; + return false; // Finally update the unconditional successor to be reached via a branch // if it would not be reached by fallthrough. - if (!isLayoutSuccessor(TBB)) + if (!isLayoutSuccessor(TBB)) { TII->InsertBranch(*this, TBB, nullptr, Cond, DL); + return true; + } } } else { if (FBB) { @@ -445,12 +449,14 @@ // conditional branch. if (isLayoutSuccessor(TBB)) { if (TII->ReverseBranchCondition(Cond)) - return; + return false; TII->RemoveBranch(*this); TII->InsertBranch(*this, FBB, nullptr, Cond, DL); + return true; } else if (isLayoutSuccessor(FBB)) { TII->RemoveBranch(*this); TII->InsertBranch(*this, TBB, nullptr, Cond, DL); + return true; } } else { // Walk through the successors and find the successor which is not @@ -475,7 +481,7 @@ // if it would not be reached by fallthrough. if (!isLayoutSuccessor(TBB)) TII->InsertBranch(*this, TBB, nullptr, Cond, DL); - return; + return true; } // The block has a fallthrough conditional branch. @@ -484,16 +490,19 @@ // We can't reverse the condition, add an unconditional branch. Cond.clear(); TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, DL); - return; + return true; } TII->RemoveBranch(*this); TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, DL); + return true; } else if (!isLayoutSuccessor(FallthroughBB)) { TII->RemoveBranch(*this); TII->InsertBranch(*this, TBB, FallthroughBB, Cond, DL); + return true; } } } + return false; } void MachineBasicBlock::validateSuccProbs() const {