-
Notifications
You must be signed in to change notification settings - Fork 14.3k
MachineCopyPropagation: Do not remove copies preserved by regmask #125868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-llvm-regalloc Author: Jinsong Ji (jsji) Changesllvm/llvm-project@9e436c2 tries to handle register masks and We delete the copies without invalidate all the use in the CopyInfo, so Full diff: https://github.com/llvm/llvm-project/pull/125868.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 460749a739c763..ba63d4c69d0900 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->dump());
+
MaybeDead->eraseFromParent();
Changed = true;
++NumDeletes;
|
|
Co-authored-by: Matt Arsenault <[email protected]>
Fix missing )
Issue #126107 has a reproducer for this, so that can be added as a test. I've checked that applying this patch does fix that assertion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
if (MIRefedinCopyInfo) | ||
continue; | ||
|
||
LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: " << *MaybeDead; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing close-paren, which is causing the build failure.
LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: " << *MaybeDead; | |
LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: " << *MaybeDead); |
Update the `generate-tests.py` script to create new tests for `atomicrmw {fadd,fmin,fmax}` and test these with `half`, `float`, `bfloat` and `double`. Generate auto-tests to check both with and without `+lsfe`, so that when llvm#125868 is merged, `+lsfe` will use a single atomic floating-point instruction.
…vm#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: llvm#126107 --------- Co-authored-by: Matt Arsenault <[email protected]>
…vm#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: llvm#126107 --------- Co-authored-by: Matt Arsenault <[email protected]>
…vm#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: llvm#126107 --------- Co-authored-by: Matt Arsenault <[email protected]>
…vm#125868) (llvm#2525) 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: llvm#126107 --------- Co-authored-by: Matt Arsenault <[email protected]> (cherry picked from commit 5d2e284)
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