[llvm] [CodeGen] Correctly handle non-standard cases in RemoveLoadsIntoFakeUses (PR #111551)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 12:31:08 PDT 2024
================
@@ -109,31 +112,38 @@ bool RemoveLoadsIntoFakeUses::runOnMachineFunction(MachineFunction &MF) {
// reload of a spilled register.
if (MI.getRestoreSize(TII)) {
Register Reg = MI.getOperand(0).getReg();
- assert(Reg.isPhysical() && "VReg seen in function with NoVRegs set?");
// Don't delete live physreg defs, or any reserved register defs.
if (!LivePhysRegs.available(Reg) || MRI->isReserved(Reg))
continue;
- // There should be an exact match between the loaded register and the
- // FAKE_USE use. If not, this is a load that is unused by anything? It
- // should probably be deleted, but that's outside of this pass' scope.
- if (RegFakeUses.contains(Reg)) {
+ // There should typically be an exact match between the loaded register
+ // and the FAKE_USE, but sometimes regalloc will choose to load a larger
+ // value than is needed. Therefore, as long as the load isn't used by
+ // anything except at least one FAKE_USE, we will delete it. If it isn't
+ // used by any fake uses, it should still be safe to delete but we
+ // choose to ignore it so that this pass has no side effects unrelated
+ // to fake uses.
+ SmallDenseSet<MachineInstr *> FakeUsesToDelete;
+ for (MCRegUnit Unit : TRI->regunits(Reg)) {
+ if (!RegFakeUses.contains(Unit))
+ continue;
+ for (MachineInstr *FakeUse : RegFakeUses[Unit])
+ FakeUsesToDelete.insert(FakeUse);
+ RegFakeUses.erase(Unit);
----------------
arsenm wrote:
This is a lot of manual liveness work. You're already walking backwards over the function and tracking liveness. You're erasing the instruction. Why not just erase the instruction, and then check at the reload point whether the def is dead?
https://github.com/llvm/llvm-project/pull/111551
More information about the llvm-commits
mailing list