-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[CodeGen] Refactor DeadMIElim isDead and GISel isTriviallyDead #105956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,23 +80,9 @@ INITIALIZE_PASS(DeadMachineInstructionElim, DEBUG_TYPE, | |
"Remove dead machine instructions", false, false) | ||
|
||
bool DeadMachineInstructionElimImpl::isDead(const MachineInstr *MI) const { | ||
// Technically speaking inline asm without side effects and no defs can still | ||
// be deleted. But there is so much bad inline asm code out there, we should | ||
// let them be. | ||
if (MI->isInlineAsm()) | ||
return false; | ||
|
||
// Don't delete frame allocation labels. | ||
if (MI->getOpcode() == TargetOpcode::LOCAL_ESCAPE || | ||
MI->getOpcode() == TargetOpcode::FAKE_USE) | ||
return false; | ||
|
||
// Don't delete instructions with side effects. | ||
bool SawStore = false; | ||
if (!MI->isSafeToMove(SawStore) && !MI->isPHI()) | ||
return false; | ||
|
||
// Examine each operand. | ||
// Instructions without side-effects are dead iff they only define dead regs. | ||
// This function is hot and this loop returns early in the common case, | ||
// so only perform additional checks before this if absolutely necessary. | ||
for (const MachineOperand &MO : MI->all_defs()) { | ||
Register Reg = MO.getReg(); | ||
if (Reg.isPhysical()) { | ||
|
@@ -120,8 +106,18 @@ bool DeadMachineInstructionElimImpl::isDead(const MachineInstr *MI) const { | |
} | ||
} | ||
|
||
// If there are no defs with uses, the instruction is dead. | ||
return true; | ||
// Technically speaking inline asm without side effects and no defs can still | ||
// be deleted. But there is so much bad inline asm code out there, we should | ||
// let them be. | ||
if (MI->isInlineAsm()) | ||
return false; | ||
|
||
// FIXME: See issue #105950 for why LIFETIME markers are considered dead here. | ||
if (MI->isLifetimeMarker()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder why lifetime markers are considered safe to move... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like lifetime markers should be considered in MachineInstr::isPosition, which would also make them unsafe to move. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like considering isLifetimeMarker here and the opposite down in wouldBeTriviallyDead but I guess you're planning on fixing that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I want to fix this properly, but I wanted to keep this NFC except for the compile-time improvements. I think for now it's better to make this sketchy behavior explicit in DeadMIElim rather than silently dropping lifetime markers by pretending they are safe to move, which makes little sense. I want to add lifetime markers to MachineInstr::isPosition, which makes them unsafe to move. This should get rid of the ugly opposite check. |
||
return true; | ||
|
||
// If there are no defs with uses, the instruction might be dead. | ||
return MI->wouldBeTriviallyDead(); | ||
} | ||
|
||
bool DeadMachineInstructionElimImpl::runImpl(MachineFunction &MF) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't the isPhysical path consider the dead flag on the operand?