Skip to content

Commit a3543fd

Browse files
vhscampoststellar
authored andcommitted
[ARM] Handle debug instrs in ARM Low Overhead Loop pass
In function ConvertVPTBlocks(), it is assumed that every instruction within a vector-predicated block is predicated. This is false for debug instructions, used by LLVM. Because of this, an assertion failure is reached when an input contains debug instructions inside VPT blocks. In non-assert builds, an out of bounds memory access took place. The present patch properly covers the case of debug instructions. Reviewed By: dmgreen Differential Revision: https://reviews.llvm.org/D99075
1 parent c7381b6 commit a3543fd

File tree

2 files changed

+343
-7
lines changed

2 files changed

+343
-7
lines changed

llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,14 +1467,15 @@ MachineInstr* ARMLowOverheadLoops::ExpandLoopStart(LowOverheadLoop &LoLoop) {
14671467

14681468
void ARMLowOverheadLoops::ConvertVPTBlocks(LowOverheadLoop &LoLoop) {
14691469
auto RemovePredicate = [](MachineInstr *MI) {
1470+
if (MI->isDebugInstr())
1471+
return;
14701472
LLVM_DEBUG(dbgs() << "ARM Loops: Removing predicate from: " << *MI);
1471-
if (int PIdx = llvm::findFirstVPTPredOperandIdx(*MI)) {
1472-
assert(MI->getOperand(PIdx).getImm() == ARMVCC::Then &&
1473-
"Expected Then predicate!");
1474-
MI->getOperand(PIdx).setImm(ARMVCC::None);
1475-
MI->getOperand(PIdx+1).setReg(0);
1476-
} else
1477-
llvm_unreachable("trying to unpredicate a non-predicated instruction");
1473+
int PIdx = llvm::findFirstVPTPredOperandIdx(*MI);
1474+
assert(PIdx >= 1 && "Trying to unpredicate a non-predicated instruction");
1475+
assert(MI->getOperand(PIdx).getImm() == ARMVCC::Then &&
1476+
"Expected Then predicate!");
1477+
MI->getOperand(PIdx).setImm(ARMVCC::None);
1478+
MI->getOperand(PIdx + 1).setReg(0);
14781479
};
14791480

14801481
for (auto &Block : LoLoop.getVPTBlocks()) {
@@ -1518,8 +1519,13 @@ void ARMLowOverheadLoops::ConvertVPTBlocks(LowOverheadLoop &LoLoop) {
15181519
// - Insert a new vpst to predicate the instruction(s) that following
15191520
// the divergent vpr def.
15201521
MachineInstr *Divergent = VPTState::getDivergent(Block);
1522+
MachineBasicBlock *MBB = Divergent->getParent();
15211523
auto DivergentNext = ++MachineBasicBlock::iterator(Divergent);
1524+
while (DivergentNext != MBB->end() && DivergentNext->isDebugInstr())
1525+
++DivergentNext;
1526+
15221527
bool DivergentNextIsPredicated =
1528+
DivergentNext != MBB->end() &&
15231529
getVPTInstrPredicate(*DivergentNext) != ARMVCC::None;
15241530

15251531
for (auto I = ++MachineBasicBlock::iterator(VPST), E = DivergentNext;

0 commit comments

Comments
 (0)