diff options
author | Tobias Stadler <mail@stadler-tobias.de> | 2024-09-09 16:30:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-09 16:30:44 +0200 |
commit | 2d338bed00b2bba713bceb4915400063b95929b2 (patch) | |
tree | 0bd8f325e472b3720f0708db03fcb7a2396f7f7c /llvm/lib/CodeGen/MachineInstr.cpp | |
parent | a2f659c1349cb70c09b183eb214e2a24cf04c2c6 (diff) | |
download | llvm-2d338bed00b2bba713bceb4915400063b95929b2.zip llvm-2d338bed00b2bba713bceb4915400063b95929b2.tar.gz llvm-2d338bed00b2bba713bceb4915400063b95929b2.tar.bz2 |
[CodeGen] Refactor DeadMIElim isDead and GISel isTriviallyDead (#105956)
Merge GlobalISel's isTriviallyDead and DeadMachineInstructionElim's
isDead code and remove all unnecessary checks from the hot path by
looping over the operands before doing any other checks.
See #105950 for why DeadMIElim needs to remove LIFETIME markers even
though they probably shouldn't generally be considered dead.
x86 CTMark O3: -0.1%
AArch64 GlobalISel CTMark O0: -0.6%, O2: -0.2%
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index a0f4040..0d78c2ca 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -1323,6 +1323,28 @@ bool MachineInstr::isSafeToMove(bool &SawStore) const { return true; } +bool MachineInstr::wouldBeTriviallyDead() const { + // Don't delete frame allocation labels. + // FIXME: Why is LOCAL_ESCAPE not considered in MachineInstr::isLabel? + if (getOpcode() == TargetOpcode::LOCAL_ESCAPE) + return false; + + // Don't delete FAKE_USE. + // FIXME: Why is FAKE_USE not considered in MachineInstr::isPosition? + if (isFakeUse()) + return false; + + // LIFETIME markers should be preserved. + // FIXME: Why are LIFETIME markers not considered in MachineInstr::isPosition? + if (isLifetimeMarker()) + return false; + + // If we can move an instruction, we can remove it. Otherwise, it has + // a side-effect of some sort. + bool SawStore = false; + return isPHI() || isSafeToMove(SawStore); +} + static bool MemOperandsHaveAlias(const MachineFrameInfo &MFI, AAResults *AA, bool UseTBAA, const MachineMemOperand *MMOa, const MachineMemOperand *MMOb) { |