-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Closed
Copy link
Labels
crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]llvm:codegen
Description
During our local testing, we encountered the assertion failure Reg.isPhysical() in the MachineCP pass.
Reduced reproducer:
---
name: main
body: |
bb.0.entry:
liveins: $ymm7
renamable $ymm6 = COPY killed renamable $ymm7
CALL64r killed renamable $rax, csr_64_mostregs
renamable $ymm6 = VPADDWZ256rr $ymm6, $ymm6
Steps to reproduce:
$ bin/llc -run-pass machine-cp test.mir
llc: /root/llvm-project/llvm/include/llvm/MC/MCRegisterInfo.h:649: llvm::MCRegUnitIterator::MCRegUnitIterator(llvm::MCRegister, const llvm::MCRegisterInfo*): Assertion `Reg.isPhysical()' failed
Proof: https://godbolt.org/z/PnqdcKbfe
The problematic patch seems to be: 9e436c2
Based on my investigation, the issue arises when we remove renamable $ymm6 = COPY killed renamable $ymm7 due to regmask clobbering. However, during this process, we skip dropping the corresponding RegUnit from the tracking copies, since it's preserved:
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))
if (!PreservedRegUnits.test(RegUnit))
Tracker.clobberRegUnit(RegUnit, *TRI, *TII, UseCopyInstr);
// erase() will return the next valid iterator pointing to the next
// element after the erased one.
DI = MaybeDeadCopies.erase(DI);
MaybeDead->eraseFromParent();As a result, we retain a pointer to the erased instruction in tracking copies, which leads to a failure when accessing it while processing renamable $ymm6 = VPADDWZ256rr $ymm6, $ymm6, clobbering any previous copy definitions.
@ostannard hi, could you please take a look?
Metadata
Metadata
Labels
crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]llvm:codegen