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 @@ -815,10 +815,13 @@ bool ARMLowOverheadLoops::RevertLoopDec(MachineInstr *MI) const { LLVM_DEBUG(dbgs() << "ARM Loops: Reverting to sub: " << *MI); 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/cmplx_cong.mir =================================================================== --- llvm/test/CodeGen/Thumb2/LowOverheadLoops/cmplx_cong.mir +++ llvm/test/CodeGen/Thumb2/LowOverheadLoops/cmplx_cong.mir @@ -38,13 +38,12 @@ ; CHECK-LABEL: name: arm_cmplx_conj_f32_mve ; CHECK: bb.0: ; CHECK: successors: %bb.1(0x80000000) - ; CHECK: liveins: $lr, $r0, $r1, $r3, $r4 + ; CHECK: liveins: $lr, $r0, $r1, $r2, $r4 ; CHECK: frame-setup tPUSH 14 /* CC::al */, $noreg, killed $r4, 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 $r4, -8 - ; CHECK: tCMPi8 renamable $r3, 4, 14 /* CC::al */, $noreg, implicit-def dead $cpsr - ; FIXME: tLSRi needs to be producing the value in r3 + ; CHECK: renamable $r3, dead $cpsr = tLSLri killed renamable $r2, 1, 14 /* CC::al */, $noreg ; CHECK: $r4 = t2MOVi16 target-flags(arm-lo16) @arm_cmplx_conj_f32_mve.cmplx_conj_sign, 14 /* CC::al */, $noreg ; CHECK: $r4 = t2MOVTi16 killed $r4, target-flags(arm-hi16) @arm_cmplx_conj_f32_mve.cmplx_conj_sign, 14 /* CC::al */, $noreg ; CHECK: renamable $q0 = nnan ninf nsz MVE_VLDRWU32 killed renamable $r4, 0, 0, $noreg 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