Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Apr 30, 2024

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.

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 30, 2024

@llvm/pr-subscribers-backend-risc-v

Author: Luke Lau (lukel97)

Changes

We 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:

  • (modified) llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp (+3-11)
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());

@lukel97 lukel97 changed the title [RISCV] Let LiveIntervals::shrinkToUses compute dead immediate. NFC [RISCV] Let LiveIntervals::shrinkToUses compute dead immediates. NFC Apr 30, 2024
}
// NextMI no longer uses OldVLReg so shrink its LiveInterval.
if (OldVLReg && OldVLReg.isVirtual())
LIS->shrinkToUses(&LIS->getInterval(OldVLReg), &ToDelete);
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
@lukel97 lukel97 changed the title [RISCV] Let LiveIntervals::shrinkToUses compute dead immediates. NFC [RISCV] Let LiveIntervals::shrinkToUses compute dead AVLs May 6, 2024
@lukel97 lukel97 force-pushed the insert-vsetvli-coalesce-simplify-dead-removal branch from d25a4d2 to 983ceef Compare May 6, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants