aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineCopyPropagation.cpp
diff options
context:
space:
mode:
authorJinsong Ji <jinsong.ji@intel.com>2025-02-10 12:26:33 -0500
committerGitHub <noreply@github.com>2025-02-10 12:26:33 -0500
commit5d2e2847e09ae70e24b6c749c08028e705786113 (patch)
treeebc94ddd93e8d6162a2dbab56d55891c511eea43 /llvm/lib/CodeGen/MachineCopyPropagation.cpp
parent0a470a926481d370251731cb2dd897531756335f (diff)
downloadllvm-5d2e2847e09ae70e24b6c749c08028e705786113.zip
llvm-5d2e2847e09ae70e24b6c749c08028e705786113.tar.gz
llvm-5d2e2847e09ae70e24b6c749c08028e705786113.tar.bz2
MachineCopyPropagation: Do not remove copies preserved by regmask (#125868)
llvm/llvm-project@9e436c2daa44 tries to handle register masks and sub-registers, it avoids clobbering RegUnit presreved by regmask. But it then introduces invalid pointer issues. We delete the copies without invalidate all the use in the CopyInfo, so we dereferenced invalid pointers in next interation, causing asserts. Fixes: #126107 --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
Diffstat (limited to 'llvm/lib/CodeGen/MachineCopyPropagation.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 4d9d712..1105b8c 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -1018,18 +1018,30 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
continue;
}
- LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: ";
- MaybeDead->dump());
-
// Invalidate all entries in the copy map which are not preserved by
// this register mask.
- for (unsigned RegUnit : TRI->regunits(Reg))
+ bool MIRefedinCopyInfo = false;
+ for (unsigned RegUnit : TRI->regunits(Reg)) {
if (!PreservedRegUnits.test(RegUnit))
Tracker.clobberRegUnit(RegUnit, *TRI, *TII, UseCopyInstr);
+ else {
+ if (MaybeDead == Tracker.findCopyForUnit(RegUnit, *TRI)) {
+ MIRefedinCopyInfo = true;
+ }
+ }
+ }
// erase() will return the next valid iterator pointing to the next
// element after the erased one.
DI = MaybeDeadCopies.erase(DI);
+
+ // Preserved by RegMask, DO NOT remove copy
+ if (MIRefedinCopyInfo)
+ continue;
+
+ LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: "
+ << *MaybeDead);
+
MaybeDead->eraseFromParent();
Changed = true;
++NumDeletes;