diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-04-29 21:52:13 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-04-29 21:52:13 +0000 |
commit | 701c21ea107280011c74cb0c41e9db9a3bd30cee (patch) | |
tree | 4dd56eacbc085b8b6c7b3a46c3b13cb4ff8e0279 /llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp | |
parent | bf5ef7b63b8b7ed3c166041444355efd442fe6f4 (diff) | |
download | bcm5719-llvm-701c21ea107280011c74cb0c41e9db9a3bd30cee.tar.gz bcm5719-llvm-701c21ea107280011c74cb0c41e9db9a3bd30cee.zip |
AMDGPU: Fix crash with unreachable terminators.
If a block has no successors because it ends in unreachable,
this was accessing an invalid iterator.
Also stop counting instructions that don't emit any
real instructions.
llvm-svn: 268119
Diffstat (limited to 'llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp')
-rw-r--r-- | llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp b/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp index 6bac47e639b..da7cb5f63b9 100644 --- a/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp +++ b/llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp @@ -125,29 +125,44 @@ FunctionPass *llvm::createSILowerControlFlowPass() { return new SILowerControlFlow(); } +static bool opcodeEmitsNoInsts(unsigned Opc) { + switch (Opc) { + case TargetOpcode::IMPLICIT_DEF: + case TargetOpcode::KILL: + case TargetOpcode::BUNDLE: + case TargetOpcode::CFI_INSTRUCTION: + case TargetOpcode::EH_LABEL: + case TargetOpcode::GC_LABEL: + case TargetOpcode::DBG_VALUE: + return true; + default: + return false; + } +} + bool SILowerControlFlow::shouldSkip(MachineBasicBlock *From, MachineBasicBlock *To) { unsigned NumInstr = 0; + MachineFunction *MF = From->getParent(); - for (MachineFunction::iterator MBBI = MachineFunction::iterator(From), - ToI = MachineFunction::iterator(To); MBBI != ToI; ++MBBI) { - + for (MachineFunction::iterator MBBI(From), ToI(To), End = MF->end(); + MBBI != End && MBBI != ToI; ++MBBI) { MachineBasicBlock &MBB = *MBBI; for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); NumInstr < SkipThreshold && I != E; ++I) { + if (opcodeEmitsNoInsts(I->getOpcode())) + continue; - if (I->isBundle() || !I->isBundled()) { - // When a uniform loop is inside non-uniform control flow, the branch - // leaving the loop might be an S_CBRANCH_VCCNZ, which is never taken - // when EXEC = 0. We should skip the loop lest it becomes infinite. - if (I->getOpcode() == AMDGPU::S_CBRANCH_VCCNZ) - return true; + // When a uniform loop is inside non-uniform control flow, the branch + // leaving the loop might be an S_CBRANCH_VCCNZ, which is never taken + // when EXEC = 0. We should skip the loop lest it becomes infinite. + if (I->getOpcode() == AMDGPU::S_CBRANCH_VCCNZ) + return true; - if (++NumInstr >= SkipThreshold) - return true; - } + if (++NumInstr >= SkipThreshold) + return true; } } |