- // Predicate the 'false' block.
- std::vector<MachineOperand> NewCond(BBI.Cond);
- TII->ReverseBranchCondition(NewCond);
- PredicateBlock(BBI.FalseBB, NewCond, true);
-
- // Add a conditional branch to 'false' successor if needed.
- if (FalseNeedCBr)
- TII->InsertBranch(*BBI.FalseBB, *BBI.FalseBB->succ_begin(), NULL,NewCond);
-
- // Merge the 'true' and 'false' blocks by copying the instructions
- // from the 'false' block to the 'true' block. That is, unless the true
- // block would clobber the predicate, in that case, do the opposite.
- BBInfo *CvtBBI;
- if (!TrueBBI.ClobbersPred) {
- MergeBlocks(TrueBBI, FalseBBI);
- CvtBBI = &TrueBBI;
- } else {
- MergeBlocks(FalseBBI, TrueBBI);
- CvtBBI = &FalseBBI;
- }
+ // Remove the duplicated instructions from the 'true' block.
+ for (unsigned i = 0, e = Dups.size(); i != e; ++i) {
+ Dups[i]->eraseFromParent();
+ --TrueBBI.Size;
+ }
+
+ // Predicate the 'true' block after removing its branch.
+ TrueBBI.Size -= TII->RemoveBranch(*BBI.TrueBB);
+ PredicateBlock(BBI.TrueBB, BBI.Cond);
+
+ // Add a conditional branch to 'true' successor if needed.
+ if (TrueNeedCBr && TrueBBI.ClobbersPred &&
+ isNextBlock(BBI.TrueBB, *BBI.TrueBB->succ_begin()))
+ TrueNeedCBr = false;
+ if (TrueNeedCBr)
+ TII->InsertBranch(*BBI.TrueBB, *BBI.TrueBB->succ_begin(), NULL, BBI.Cond);
+
+ // Predicate the 'false' block.
+ std::vector<MachineOperand> NewCond(BBI.Cond);
+ TII->ReverseBranchCondition(NewCond);
+ PredicateBlock(BBI.FalseBB, NewCond, true);
+
+ // Add a conditional branch to 'false' successor if needed.
+ if (FalseNeedCBr && !TrueBBI.ClobbersPred &&
+ isNextBlock(BBI.FalseBB, *BBI.FalseBB->succ_begin()))
+ FalseNeedCBr = false;
+ if (FalseNeedCBr)
+ TII->InsertBranch(*BBI.FalseBB, *BBI.FalseBB->succ_begin(), NULL,NewCond);
+
+ // Merge the 'true' and 'false' blocks by copying the instructions
+ // from the 'false' block to the 'true' block. That is, unless the true
+ // block would clobber the predicate, in that case, do the opposite.
+ BBInfo *CvtBBI;
+ if (!TrueBBI.ClobbersPred) {
+ MergeBlocks(TrueBBI, FalseBBI);
+ CvtBBI = &TrueBBI;
+ } else {
+ MergeBlocks(FalseBBI, TrueBBI);
+ CvtBBI = &FalseBBI;
+ }