[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 09:04:04 PDT 2024
================
@@ -113,27 +115,34 @@ bool RemoveLoadsIntoFakeUses::runOnMachineFunction(MachineFunction &MF) {
// 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)) {
- LLVM_DEBUG(dbgs() << "RemoveLoadsIntoFakeUses: DELETING: " << MI);
- // It is possible that some DBG_VALUE instructions refer to this
- // instruction. They will be deleted in the live debug variable
- // analysis.
- MI.eraseFromParent();
- AnyChanges = true;
- ++NumLoadsDeleted;
- // Each FAKE_USE now appears to be a fake use of the previous value
- // of the loaded register; delete them to avoid incorrectly
- // interpreting them as such.
- for (MachineInstr *FakeUse : RegFakeUses[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.
+ bool HasFakeUse = false;
+ for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg)) {
----------------
arsenm wrote:
You shouldn't need to consider sub registers. Do everything in terms of register units, and liveness queries on the instruction
https://github.com/llvm/llvm-project/pull/111551
More information about the llvm-commits
mailing list