@@ -1351,6 +1351,43 @@ bool MachineInstr::wouldBeTriviallyDead() const {
13511351 return isPHI () || isSafeToMove (SawStore);
13521352}
13531353
1354+ bool MachineInstr::isDead (const MachineRegisterInfo &MRI,
1355+ LiveRegUnits *LivePhysRegs) const {
1356+ // Technically speaking inline asm without side effects and no defs can still
1357+ // be deleted. But there is so much bad inline asm code out there, we should
1358+ // let them be.
1359+ if (isInlineAsm ())
1360+ return false ;
1361+
1362+ // If we suspect this instruction may have some side-effects, then we say
1363+ // this instruction cannot be dead.
1364+ // FIXME: See issue #105950 for why LIFETIME markers are considered dead here.
1365+ if (!isLifetimeMarker () && !wouldBeTriviallyDead ())
1366+ return false ;
1367+
1368+ // Instructions without side-effects are dead iff they only define dead regs.
1369+ // This function is hot and this loop returns early in the common case,
1370+ // so only perform additional checks before this if absolutely necessary.
1371+ for (const MachineOperand &MO : all_defs ()) {
1372+ Register Reg = MO.getReg ();
1373+ if (Reg.isPhysical ()) {
1374+ // Don't delete live physreg defs, or any reserved register defs.
1375+ if (!LivePhysRegs || !LivePhysRegs->available (Reg) || MRI.isReserved (Reg))
1376+ return false ;
1377+ } else {
1378+ if (MO.isDead ())
1379+ continue ;
1380+ for (const MachineInstr &Use : MRI.use_nodbg_instructions (Reg)) {
1381+ if (&Use != this )
1382+ // This def has a non-debug use. Don't delete the instruction!
1383+ return false ;
1384+ }
1385+ }
1386+ }
1387+
1388+ return true ;
1389+ }
1390+
13541391static bool MemOperandsHaveAlias (const MachineFrameInfo &MFI, AAResults *AA,
13551392 bool UseTBAA, const MachineMemOperand *MMOa,
13561393 const MachineMemOperand *MMOb) {
@@ -1593,43 +1630,6 @@ bool MachineInstr::allImplicitDefsAreDead() const {
15931630 return true ;
15941631}
15951632
1596- bool MachineInstr::isDead (const MachineRegisterInfo *MRI,
1597- LiveRegUnits *LivePhysRegs) const {
1598- // Instructions without side-effects are dead iff they only define dead regs.
1599- // This function is hot and this loop returns early in the common case,
1600- // so only perform additional checks before this if absolutely necessary.
1601- for (const MachineOperand &MO : all_defs ()) {
1602- Register Reg = MO.getReg ();
1603- if (Reg.isPhysical ()) {
1604- // Don't delete live physreg defs, or any reserved register defs.
1605- if (!LivePhysRegs || !LivePhysRegs->available (Reg) ||
1606- MRI->isReserved (Reg))
1607- return false ;
1608- } else {
1609- if (MO.isDead ())
1610- continue ;
1611- for (const MachineInstr &Use : MRI->use_nodbg_instructions (Reg)) {
1612- if (&Use != this )
1613- // This def has a non-debug use. Don't delete the instruction!
1614- return false ;
1615- }
1616- }
1617- }
1618-
1619- // Technically speaking inline asm without side effects and no defs can still
1620- // be deleted. But there is so much bad inline asm code out there, we should
1621- // let them be.
1622- if (isInlineAsm ())
1623- return false ;
1624-
1625- // FIXME: See issue #105950 for why LIFETIME markers are considered dead here.
1626- if (isLifetimeMarker ())
1627- return true ;
1628-
1629- // If there are no defs with uses, the instruction might be dead.
1630- return wouldBeTriviallyDead ();
1631- }
1632-
16331633// / copyImplicitOps - Copy implicit register operands from specified
16341634// / instruction to this instruction.
16351635void MachineInstr::copyImplicitOps (MachineFunction &MF,
0 commit comments