void combineMasks(MachineInstr &MI);
+ bool removeMBBifRedundant(MachineBasicBlock &MBB);
+
void process(MachineInstr &MI);
// Skip to the next instruction, ignoring debug instructions, and trivial
AU.addPreserved<SlotIndexes>();
AU.addPreserved<LiveIntervals>();
AU.addPreservedID(LiveVariablesID);
- AU.addPreservedID(MachineLoopInfoID);
- AU.addPreservedID(MachineDominatorsID);
- AU.setPreservesCFG();
MachineFunctionPass::getAnalysisUsage(AU);
}
};
if (LIS)
LIS->RemoveMachineInstrFromMaps(*MI);
MI->eraseFromParent();
+ removeMBBifRedundant(MBB);
}
}
}
}
}
+bool SILowerControlFlow::removeMBBifRedundant(MachineBasicBlock &MBB) {
+ bool Redundant = true;
+ for (auto &I : MBB.instrs()) {
+ if (!I.isDebugInstr() && !I.isUnconditionalBranch())
+ Redundant = false;
+ }
+ if (Redundant) {
+ MachineBasicBlock *Succ = *MBB.succ_begin();
+ SmallVector<MachineBasicBlock *, 2> Preds(MBB.predecessors());
+ for (auto P : Preds) {
+ P->replaceSuccessor(&MBB, Succ);
+ MachineBasicBlock::iterator I(P->getFirstInstrTerminator());
+ while (I != P->end()) {
+ if (I->isBranch()) {
+ if (TII->getBranchDestBlock(*I) == &MBB) {
+ I->getOperand(0).setMBB(Succ);
+ break;
+ }
+ }
+ I++;
+ }
+ if (I == P->end()) {
+ MachineFunction *MF = P->getParent();
+ MachineFunction::iterator InsertPt =
+ P->getNextNode() ? MachineFunction::iterator(P->getNextNode())
+ : MF->end();
+ MF->splice(InsertPt, Succ);
+ }
+ }
+ MBB.removeSuccessor(Succ);
+ if (LIS) {
+ for (auto &I : MBB.instrs())
+ LIS->RemoveMachineInstrFromMaps(I);
+ }
+ MBB.clear();
+ MBB.eraseFromParent();
+ return true;
+ }
+ return false;
+}
+
bool SILowerControlFlow::runOnMachineFunction(MachineFunction &MF) {
const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
TII = ST.getInstrInfo();
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
; GCN: S_CBRANCH_EXECZ %bb.4, implicit $exec
; GCN: bb.1:
- ; GCN: successors: %bb.2(0x40000000), %bb.3(0x40000000)
+ ; GCN: successors: %bb.2(0x40000000), %bb.4(0x40000000)
; GCN: [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
; GCN: [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
- ; GCN: S_CBRANCH_EXECZ %bb.3, implicit $exec
+ ; GCN: S_CBRANCH_EXECZ %bb.4, implicit $exec
; GCN: bb.2:
- ; GCN: successors: %bb.3(0x80000000)
- ; GCN: bb.3:
; GCN: successors: %bb.4(0x80000000)
- ; GCN: DBG_VALUE
; GCN: bb.4:
; GCN: $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
; GCN: DBG_VALUE
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
; GCN: S_CBRANCH_EXECZ %bb.5, implicit $exec
; GCN: bb.1:
- ; GCN: successors: %bb.2(0x40000000), %bb.3(0x40000000)
+ ; GCN: successors: %bb.2(0x40000000), %bb.4(0x40000000)
; GCN: [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
; GCN: [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
- ; GCN: S_CBRANCH_EXECZ %bb.3, implicit $exec
+ ; GCN: S_CBRANCH_EXECZ %bb.4, implicit $exec
; GCN: bb.2:
- ; GCN: successors: %bb.3(0x80000000)
- ; GCN: bb.3:
; GCN: successors: %bb.4(0x80000000)
; GCN: bb.4:
; GCN: successors: %bb.5(0x80000000)
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
; GCN: S_CBRANCH_EXECZ %bb.5, implicit $exec
; GCN: bb.1:
- ; GCN: successors: %bb.2(0x40000000), %bb.3(0x40000000)
+ ; GCN: successors: %bb.2(0x40000000), %bb.4(0x40000000)
; GCN: [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
; GCN: [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
- ; GCN: S_CBRANCH_EXECZ %bb.3, implicit $exec
+ ; GCN: S_CBRANCH_EXECZ %bb.4, implicit $exec
; GCN: bb.2:
- ; GCN: successors: %bb.3(0x80000000)
- ; GCN: bb.3:
; GCN: successors: %bb.4(0x80000000)
; GCN: bb.4:
; GCN: successors: %bb.5(0x80000000)
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
; GCN: S_CBRANCH_EXECZ %bb.4, implicit $exec
; GCN: bb.1:
- ; GCN: successors: %bb.2(0x40000000), %bb.3(0x40000000)
+ ; GCN: successors: %bb.2(0x40000000), %bb.5(0x40000000)
; GCN: [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
; GCN: [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
; GCN: $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
- ; GCN: S_CBRANCH_EXECZ %bb.3, implicit $exec
+ ; GCN: S_CBRANCH_EXECZ %bb.5, implicit $exec
; GCN: bb.2:
- ; GCN: successors: %bb.3(0x80000000)
- ; GCN: bb.3:
; GCN: successors: %bb.5(0x80000000)
- ; GCN: S_BRANCH %bb.5
- ; GCN: bb.4:
- ; GCN: $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
- ; GCN: S_ENDPGM 0
; GCN: bb.5:
; GCN: successors: %bb.4(0x80000000)
; GCN: S_BRANCH %bb.4
+ ; GCN: bb.4:
+ ; GCN: $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
+ ; GCN: S_ENDPGM 0
bb.0:
successors: %bb.1, %bb.4