@@ -125,6 +125,7 @@ class TwoAddressInstructionPass : public MachineFunctionPass {
125125 bool isCopyToReg (MachineInstr &MI, Register &SrcReg, Register &DstReg,
126126 bool &IsSrcPhys, bool &IsDstPhys) const ;
127127
128+ bool isPlainlyKilled (const MachineInstr *MI, LiveRange &LR) const ;
128129 bool isPlainlyKilled (const MachineInstr *MI, Register Reg) const ;
129130 bool isPlainlyKilled (const MachineOperand &MO) const ;
130131
@@ -305,27 +306,37 @@ bool TwoAddressInstructionPass::isCopyToReg(MachineInstr &MI, Register &SrcReg,
305306 return true ;
306307}
307308
309+ bool TwoAddressInstructionPass::isPlainlyKilled (const MachineInstr *MI,
310+ LiveRange &LR) const {
311+ // This is to match the kill flag version where undefs don't have kill flags.
312+ if (!LR.hasAtLeastOneValue ())
313+ return false ;
314+
315+ SlotIndex useIdx = LIS->getInstructionIndex (*MI);
316+ LiveInterval::const_iterator I = LR.find (useIdx);
317+ assert (I != LR.end () && " Reg must be live-in to use." );
318+ return !I->end .isBlock () && SlotIndex::isSameInstr (I->end , useIdx);
319+ }
320+
308321// / Test if the given register value, which is used by the
309322// / given instruction, is killed by the given instruction.
310323bool TwoAddressInstructionPass::isPlainlyKilled (const MachineInstr *MI,
311324 Register Reg) const {
312- if (LIS && Reg. isVirtual () && !LIS-> isNotInMIMap (*MI)) {
313- // FIXME: Sometimes tryInstructionTransform() will add instructions and
314- // test whether they can be folded before keeping them. In this case it
315- // sets a kill before recursively calling tryInstructionTransform() again.
316- // If there is no interval available, we assume that this instruction is
317- // one of those. A kill flag is manually inserted on the operand so the
318- // check below will handle it.
319- LiveInterval &LI = LIS-> getInterval (Reg);
320- // This is to match the kill flag version where undefs don't have kill
321- // flags .
322- if (!LI. hasAtLeastOneValue ( ))
325+ // FIXME: Sometimes tryInstructionTransform () will add instructions and
326+ // test whether they can be folded before keeping them. In this case it
327+ // sets a kill before recursively calling tryInstructionTransform() again.
328+ // If there is no interval available, we assume that this instruction is
329+ // one of those. A kill flag is manually inserted on the operand so the
330+ // check below will handle it.
331+ if (LIS && !LIS-> isNotInMIMap (*MI)) {
332+ if (Reg. isVirtual ())
333+ return isPlainlyKilled (MI, LIS-> getInterval (Reg));
334+ // Reserved registers are considered always live .
335+ if (MRI-> isReserved (Reg ))
323336 return false ;
324-
325- SlotIndex useIdx = LIS->getInstructionIndex (*MI);
326- LiveInterval::const_iterator I = LI.find (useIdx);
327- assert (I != LI.end () && " Reg must be live-in to use." );
328- return !I->end .isBlock () && SlotIndex::isSameInstr (I->end , useIdx);
337+ return all_of (TRI->regunits (Reg), [&](MCRegUnit U) {
338+ return isPlainlyKilled (MI, LIS->getRegUnit (U));
339+ });
329340 }
330341
331342 return MI->killsRegister (Reg);
0 commit comments