-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[RISCV] Let LiveIntervals::shrinkToUses compute dead AVLs #90629
base: main
Are you sure you want to change the base?
[RISCV] Let LiveIntervals::shrinkToUses compute dead AVLs #90629
Conversation
@llvm/pr-subscribers-backend-risc-v Author: Luke Lau (lukel97) ChangesWe can simplify removing dead AVL immediates > 31 by using the dead argument to shrinkToUses, since it will already compute dead values. Full diff: https://github.com/llvm/llvm-project/pull/90629.diff 1 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 216dc78085204e..f4ff17f7b65585 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -1648,17 +1648,9 @@ bool RISCVCoalesceVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) {
if (NextMI->getOperand(1).isReg())
NextMI->getOperand(1).setReg(RISCV::NoRegister);
- if (OldVLReg && OldVLReg.isVirtual()) {
- // NextMI no longer uses OldVLReg so shrink its LiveInterval.
- LIS->shrinkToUses(&LIS->getInterval(OldVLReg));
-
- MachineInstr *VLOpDef = MRI->getUniqueVRegDef(OldVLReg);
- if (VLOpDef && TII->isAddImmediate(*VLOpDef, OldVLReg) &&
- MRI->use_nodbg_empty(OldVLReg)) {
- VLOpDef->eraseFromParent();
- LIS->removeInterval(OldVLReg);
- }
- }
+ // NextMI no longer uses OldVLReg so shrink its LiveInterval.
+ if (OldVLReg && OldVLReg.isVirtual())
+ LIS->shrinkToUses(&LIS->getInterval(OldVLReg), &ToDelete);
MI.setDesc(NextMI->getDesc());
}
MI.getOperand(2).setImm(NextMI->getOperand(2).getImm());
|
} | ||
// NextMI no longer uses OldVLReg so shrink its LiveInterval. | ||
if (OldVLReg && OldVLReg.isVirtual()) | ||
LIS->shrinkToUses(&LIS->getInterval(OldVLReg), &ToDelete); |
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.
I don't think this change is correct. It looks like ShrinkToUses only considers whether definitions are dead, and expects it's callers to validate that the instructions are safe to actually delete. This code doesn't do the required checks, and thus this seemingly obvious change actually introduces a correctness issue.
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.
Yeah, looks like RegisterCoalescer is the main user of this which eventually passes the dead instructions to LiveRangeEdit::eliminateDeadDefs
, which in turn checks for bundles, inline asm and isSafeToMove
We can simplify removing dead AVL immediates > 31 by using the dead argument to shrinkToUses, since it will already compute dead values.
d25a4d2
to
983ceef
Compare
We currently manually removing dead AVL defs if they are ADDIs used to materialize immediates > 31.
shrinkToUses already computes dead instructions though, so this patch uses it to generalize to any type of dead def.