MachineBasicBlock *NextBB = &*I;
if (TBB == NextBB && !Cond.empty() && !FBB) {
if (!TII->ReverseBranchCondition(Cond)) {
+ // XXX-disabled: Don't fold conditional branches that we added
+ // intentionally.
+ MachineBasicBlock::iterator I = CurMBB->getLastNonDebugInstr();
+ if (I != CurMBB->end()) {
+ if (I->isConditionalBranch()) {
+ return;
+ }
+ }
+
TII->RemoveBranch(*CurMBB);
TII->InsertBranch(*CurMBB, SuccBB, nullptr, Cond, dl);
return;
return true;
}
-static bool hasIdenticalMMOs(const MachineInstr *MI1, const MachineInstr *MI2) {
- auto I1 = MI1->memoperands_begin(), E1 = MI1->memoperands_end();
- auto I2 = MI2->memoperands_begin(), E2 = MI2->memoperands_end();
- if ((E1 - I1) != (E2 - I2))
- return false;
- for (; I1 != E1; ++I1, ++I2) {
- if (**I1 != **I2)
- return false;
- }
- return true;
-}
-
static void
removeMMOsFromMemoryOperations(MachineBasicBlock::iterator MBBIStartPos,
MachineBasicBlock &MBBCommon) {
assert(MBBICommon->isIdenticalTo(&*MBBI) && "Expected matching MIIs!");
if (MBBICommon->mayLoad() || MBBICommon->mayStore())
- if (!hasIdenticalMMOs(&*MBBI, &*MBBICommon))
- MBBICommon->clearMemRefs();
+ MBBICommon->setMemRefs(MBBICommon->mergeMemRefsWith(*MBBI));
++MBBI;
++MBBICommon;
// If the previous branch *only* branches to *this* block (conditional or
// not) remove the branch.
if (PriorTBB == MBB && !PriorFBB) {
+ // XXX-disabled: Don't fold conditional branches that we added
+ // intentionally.
+ MachineBasicBlock::iterator I = PrevBB.getLastNonDebugInstr();
+ if (I != PrevBB.end()) {
+ if (I->isConditionalBranch()) {
+ return MadeChange ;
+ }
+ }
+
TII->RemoveBranch(PrevBB);
MadeChange = true;
++NumBranchOpts;
// If the prior block branches somewhere else on the condition and here if
// the condition is false, remove the uncond second branch.
if (PriorFBB == MBB) {
+ // XXX-disabled: Don't fold conditional branches that we added
+ // intentionally.
+ MachineBasicBlock::iterator I = PrevBB.getLastNonDebugInstr();
+ if (I != PrevBB.end()) {
+ if (I->isConditionalBranch()) {
+ return MadeChange ;
+ }
+ }
+
DebugLoc dl = getBranchDebugLoc(PrevBB);
TII->RemoveBranch(PrevBB);
TII->InsertBranch(PrevBB, PriorTBB, nullptr, PriorCond, dl);
// if the branch condition is reversible, reverse the branch to create a
// fall-through.
if (PriorTBB == MBB) {
+ // XXX-disabled: Don't fold conditional branches that we added
+ // intentionally.
+ MachineBasicBlock::iterator I = PrevBB.getLastNonDebugInstr();
+ if (I != PrevBB.end()) {
+ if (I->isConditionalBranch()) {
+ return MadeChange ;
+ }
+ }
+
SmallVector<MachineOperand, 4> NewPriorCond(PriorCond);
if (!TII->ReverseBranchCondition(NewPriorCond)) {
DebugLoc dl = getBranchDebugLoc(PrevBB);