@@ -399,10 +399,7 @@ void RISCVLiveVariables::markKills(MachineFunction &MF) {
399399 }
400400
401401 for (MachineInstr &MI : reverse (*MBB)) {
402- for (MachineOperand &MO : MI.operands ()) {
403- if (!MO.isReg ())
404- continue ;
405-
402+ for (MachineOperand &MO : MI.all_defs ()) {
406403 Register Reg = MO.getReg ();
407404 // Does not track physical registers pre-regalloc.
408405 if ((PreRegAlloc && Reg.isPhysical ()) ||
@@ -413,20 +410,28 @@ void RISCVLiveVariables::markKills(MachineFunction &MF) {
413410 " Register not tracked" );
414411 auto RegIdx = PreRegAlloc ? TrackedRegisters[Reg] : Reg.asMCReg ().id ();
415412
416- if (MO.isDef ()) {
417- KillSet.set (RegIdx);
413+ KillSet.set (RegIdx);
418414
419- // Also handle sub-registers for physical registers
420- if (!PreRegAlloc && Reg.isPhysical ()) {
421- for (MCRegAliasIterator RA (Reg, TRI, true ); RA.isValid (); ++RA)
422- KillSet.set (*RA);
423- }
424- continue ;
415+ // Also handle sub-registers for physical registers
416+ if (!PreRegAlloc && Reg.isPhysical ()) {
417+ for (MCRegAliasIterator RA (Reg, TRI, true ); RA.isValid (); ++RA)
418+ KillSet.set (*RA);
425419 }
420+ }
421+
422+ for (MachineOperand &MO : MI.all_uses ()) {
423+ Register Reg = MO.getReg ();
424+ // Does not track physical registers pre-regalloc.
425+ if ((PreRegAlloc && Reg.isPhysical ()) ||
426+ !isTrackableRegister (Reg, TRI, MRI))
427+ continue ;
428+
429+ assert (TrackedRegisters.find (Reg) != TrackedRegisters.end () &&
430+ " Register not tracked" );
431+ auto RegIdx = PreRegAlloc ? TrackedRegisters[Reg] : Reg.asMCReg ().id ();
426432
427- // Use.
428433 if (KillSet[RegIdx]) {
429- if (!MO.isKill () && !MI.isPHI () && !MI. isCall () )
434+ if (!MO.isKill () && !MI.isPHI ())
430435 MO.setIsKill (true );
431436 LLVM_DEBUG (dbgs () << " Marking kill of " << printReg (Reg, TRI)
432437 << " at instruction: " << MI);
0 commit comments