bool needMigrateBlock(MachineBasicBlock *MBB) const;
// Utility Functions
- void reversePredicateSetter(MachineBasicBlock::iterator I);
+ void reversePredicateSetter(MachineBasicBlock::iterator I,
+ MachineBasicBlock &MBB);
/// Compute the reversed DFS post order of Blocks
void orderBlocks(MachineFunction *MF);
}
void AMDGPUCFGStructurizer::reversePredicateSetter(
- MachineBasicBlock::iterator I) {
+ MachineBasicBlock::iterator I, MachineBasicBlock &MBB) {
assert(I.isValid() && "Expected valid iterator");
for (;; --I) {
+ if (I == MBB.end())
+ continue;
if (I->getOpcode() == AMDGPU::PRED_X) {
switch (I->getOperand(2).getImm()) {
case OPCODE_IS_ZERO_INT:
// Triangle pattern, true is empty
// We reverse the predicate to make a triangle, empty false pattern;
std::swap(TrueMBB, FalseMBB);
- reversePredicateSetter(MBB->end());
+ reversePredicateSetter(MBB->end(), *MBB);
LandBlk = FalseMBB;
FalseMBB = nullptr;
} else if (FalseMBB->succ_size() == 1
MachineBasicBlock *TrueBranch = getTrueBranch(BranchMI);
MachineBasicBlock::iterator I = BranchMI;
if (TrueBranch != LandMBB)
- reversePredicateSetter(I);
+ reversePredicateSetter(I, *I->getParent());
insertCondBranchBefore(ExitingMBB, I, AMDGPU::IF_PREDICATE_SET, AMDGPU::PREDICATE_BIT, DL);
insertInstrBefore(I, AMDGPU::BREAK);
insertInstrBefore(I, AMDGPU::ENDIF);
SILoadStoreOptimizer::findMatchingDSInst(MachineBasicBlock::iterator I,
unsigned EltSize){
MachineBasicBlock::iterator E = I->getParent()->end();
+ MachineBasicBlock &MBB = *I->getParent();
MachineBasicBlock::iterator MBBI = I;
++MBBI;
- if (MBBI->getOpcode() != I->getOpcode())
+ if (MBBI == MBB.end() || MBBI->getOpcode() != I->getOpcode())
return E;
// Don't merge volatiles.