Index: llvm/lib/CodeGen/ReachingDefAnalysis.cpp =================================================================== --- llvm/lib/CodeGen/ReachingDefAnalysis.cpp +++ llvm/lib/CodeGen/ReachingDefAnalysis.cpp @@ -100,14 +100,9 @@ unsigned MBBNumber = MI->getParent()->getNumber(); assert(MBBNumber < MBBReachingDefs.size() && "Unexpected basic block number."); - const MCInstrDesc &MCID = MI->getDesc(); - for (unsigned i = 0, - e = MI->isVariadic() ? MI->getNumOperands() : MCID.getNumDefs(); - i != e; ++i) { - MachineOperand &MO = MI->getOperand(i); - if (!MO.isReg() || !MO.getReg()) - continue; - if (MO.isUse()) + + for (auto &MO : MI->operands()) { + if (!MO.isReg() || !MO.getReg() || MO.isUse()) continue; for (MCRegUnitIterator Unit(MO.getReg(), TRI); Unit.isValid(); ++Unit) { // This instruction explicitly defines the current reg unit. @@ -530,9 +525,12 @@ Dead.insert(MI); auto IsDead = [this](MachineInstr *Def, int PhysReg) { unsigned LiveDefs = 0; - for (auto &MO : Def->defs()) + for (auto &MO : Def->operands()) { + if (!MO.isReg() || !MO.getReg() || MO.isUse()) + continue; if (!MO.isDead()) ++LiveDefs; + } if (LiveDefs > 1) return false; @@ -542,8 +540,8 @@ return Uses.size() == 1; }; - for (auto &MO : MI->uses()) { - if (!MO.isReg() || MO.getReg() == 0 || !MO.isKill()) + for (auto &MO : MI->operands()) { + if (!MO.isReg() || !MO.getReg() || !MO.isUse() || !MO.isKill()) continue; if (MachineInstr *Def = getReachingLocalMIDef(MI, MO.getReg())) if (IsDead(Def, MO.getReg())) Index: llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp =================================================================== --- llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp +++ llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp @@ -817,8 +817,12 @@ MachineBasicBlock *MBB = MI->getParent(); MachineInstr *Last = &MBB->back(); SmallPtrSet Ignore; - if (Last->getOpcode() == ARM::t2LoopEnd) - Ignore.insert(Last); + for (auto I = MachineBasicBlock::iterator(MI), E = MBB->end(); I != E; ++I) { + if (I->getOpcode() == ARM::t2LoopEnd) { + Ignore.insert(&*I); + break; + } + } // If nothing defines CPSR between LoopDec and LoopEnd, use a t2SUBS. bool SetFlags = RDA->isSafeToDefRegAt(MI, ARM::CPSR, Ignore); Index: llvm/test/CodeGen/Thumb2/LowOverheadLoops/dont-ignore-vctp.mir =================================================================== --- llvm/test/CodeGen/Thumb2/LowOverheadLoops/dont-ignore-vctp.mir +++ llvm/test/CodeGen/Thumb2/LowOverheadLoops/dont-ignore-vctp.mir @@ -95,12 +95,12 @@ ; CHECK-LABEL: name: dont_ignore_vctp ; CHECK: bb.0.entry: ; CHECK: successors: %bb.1(0x80000000) - ; CHECK: liveins: $lr, $r0, $r1, $r3, $r7 + ; CHECK: liveins: $lr, $r0, $r1, $r2, $r7 ; CHECK: frame-setup tPUSH 14 /* CC::al */, $noreg, killed $r7, killed $lr, implicit-def $sp, implicit $sp ; CHECK: frame-setup CFI_INSTRUCTION def_cfa_offset 8 ; CHECK: frame-setup CFI_INSTRUCTION offset $lr, -4 ; CHECK: frame-setup CFI_INSTRUCTION offset $r7, -8 - ; CHECK: tCMPi8 renamable $r3, 4, 14 /* CC::al */, $noreg, implicit-def dead $cpsr + ; CHECK: renamable $r3, dead $cpsr = tLSLri killed renamable $r2, 1, 14 /* CC::al */, $noreg ; CHECK: renamable $r2 = tLEApcrel %const.0, 14 /* CC::al */, $noreg ; CHECK: renamable $q0 = MVE_VLDRWU32 killed renamable $r2, 0, 0, $noreg :: (load 16 from constant-pool) ; CHECK: $lr = MVE_DLSTP_32 killed renamable $r3