Fix more dereferenced end() iterators after r278532

llvm-svn: 278587
This commit is contained in:
Hans Wennborg 2016-08-13 01:12:49 +00:00
parent 35b79c2470
commit 0dd9ed1d45
5 changed files with 16 additions and 8 deletions

View File

@ -220,7 +220,8 @@ protected:
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);
@ -422,9 +423,11 @@ bool AMDGPUCFGStructurizer::needMigrateBlock(MachineBasicBlock *MBB) const {
}
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:
@ -991,7 +994,7 @@ int AMDGPUCFGStructurizer::ifPatternMatch(MachineBasicBlock *MBB) {
// 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
@ -1501,7 +1504,7 @@ void AMDGPUCFGStructurizer::mergeLoopbreakBlock(MachineBasicBlock *ExitingMBB,
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);

View File

@ -307,7 +307,7 @@ public:
BB != BB_E; ++BB) {
MachineBasicBlock &MBB = *BB;
MachineBasicBlock::iterator I = MBB.begin();
if (I->getOpcode() == AMDGPU::CF_ALU)
if (I != MBB.end() && I->getOpcode() == AMDGPU::CF_ALU)
continue; // BB was already parsed
for (MachineBasicBlock::iterator E = MBB.end(); I != E;) {
if (isALU(*I))

View File

@ -205,6 +205,8 @@ const R600Subtarget *R600TargetLowering::getSubtarget() const {
}
static inline bool isEOP(MachineBasicBlock::iterator I) {
if (std::next(I) == I->getParent()->end())
return false;
return std::next(I)->getOpcode() == AMDGPU::RETURN;
}

View File

@ -158,10 +158,11 @@ MachineBasicBlock::iterator
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.

View File

@ -156,8 +156,10 @@ static unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB,
const TargetRegisterClass &AvailableRegs = *TRI->getGPRsForTailCall(*MF);
unsigned Opc = MBBI->getOpcode();
switch (Opc) {
if (MBBI == MBB.end())
return 0;
switch (MBBI->getOpcode()) {
default: return 0;
case TargetOpcode::PATCHABLE_RET:
case X86::RET: