@@ -38,7 +38,6 @@ class DeadMachineInstructionElimImpl {
3838 bool runImpl (MachineFunction &MF);
3939
4040private:
41- bool isDead (const MachineInstr *MI) const ;
4241 bool eliminateDeadMI (MachineFunction &MF);
4342};
4443
@@ -79,47 +78,6 @@ char &llvm::DeadMachineInstructionElimID = DeadMachineInstructionElim::ID;
7978INITIALIZE_PASS (DeadMachineInstructionElim, DEBUG_TYPE,
8079 " Remove dead machine instructions" , false , false )
8180
82- bool DeadMachineInstructionElimImpl::isDead(const MachineInstr *MI) const {
83- // Instructions without side-effects are dead iff they only define dead regs.
84- // This function is hot and this loop returns early in the common case,
85- // so only perform additional checks before this if absolutely necessary.
86- for (const MachineOperand &MO : MI->all_defs ()) {
87- Register Reg = MO.getReg ();
88- if (Reg.isPhysical ()) {
89- // Don't delete live physreg defs, or any reserved register defs.
90- if (!LivePhysRegs.available (Reg) || MRI->isReserved (Reg))
91- return false ;
92- } else {
93- if (MO.isDead ()) {
94- #ifndef NDEBUG
95- // Basic check on the register. All of them should be 'undef'.
96- for (auto &U : MRI->use_nodbg_operands (Reg))
97- assert (U.isUndef () && " 'Undef' use on a 'dead' register is found!" );
98- #endif
99- continue ;
100- }
101- for (const MachineInstr &Use : MRI->use_nodbg_instructions (Reg)) {
102- if (&Use != MI)
103- // This def has a non-debug use. Don't delete the instruction!
104- return false ;
105- }
106- }
107- }
108-
109- // Technically speaking inline asm without side effects and no defs can still
110- // be deleted. But there is so much bad inline asm code out there, we should
111- // let them be.
112- if (MI->isInlineAsm ())
113- return false ;
114-
115- // FIXME: See issue #105950 for why LIFETIME markers are considered dead here.
116- if (MI->isLifetimeMarker ())
117- return true ;
118-
119- // If there are no defs with uses, the instruction might be dead.
120- return MI->wouldBeTriviallyDead ();
121- }
122-
12381bool DeadMachineInstructionElimImpl::runImpl(MachineFunction &MF) {
12482 MRI = &MF.getRegInfo ();
12583
@@ -146,7 +104,7 @@ bool DeadMachineInstructionElimImpl::eliminateDeadMI(MachineFunction &MF) {
146104 // liveness as we go.
147105 for (MachineInstr &MI : make_early_inc_range (reverse (*MBB))) {
148106 // If the instruction is dead, delete it!
149- if (isDead (&MI )) {
107+ if (MI. isDead (*MRI, &LivePhysRegs )) {
150108 LLVM_DEBUG (dbgs () << " DeadMachineInstructionElim: DELETING: " << MI);
151109 // It is possible that some DBG_VALUE instructions refer to this
152110 // instruction. They will be deleted in the live debug variable
@@ -156,11 +114,9 @@ bool DeadMachineInstructionElimImpl::eliminateDeadMI(MachineFunction &MF) {
156114 ++NumDeletes;
157115 continue ;
158116 }
159-
160117 LivePhysRegs.stepBackward (MI);
161118 }
162119 }
163-
164120 LivePhysRegs.clear ();
165121 return AnyChanges;
166122}
0 commit comments