[llvm] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 19:49:47 PST 2023
================
@@ -1262,9 +1259,16 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
if (RISCVII::hasVLOp(TSFlags)) {
MachineOperand &VLOp = MI.getOperand(getVLOpNum(MI));
if (VLOp.isReg()) {
+ MachineInstr *VLOpDef = MRI->getVRegDef(VLOp.getReg());
+
// Erase the AVL operand from the instruction.
VLOp.setReg(RISCV::NoRegister);
VLOp.setIsKill(false);
+
+ // If the old VLOp was only used by MI, it's dead.
+ if (VLOpDef && RISCV::isLoadSImm12(*VLOpDef, /*NonZero*/ true) &&
+ MRI->use_nodbg_empty(VLOpDef->getOperand(0).getReg()))
----------------
lukel97 wrote:
Actually come to think of it we probably don't even need to check for `RISCV::isLoadSImm12(*VLOpDef, /*NonZero*/ true)` here, since the only VLOpDefs without any uses are going to be the ADDI AVLs.
```suggestion
if (VLOpDef &&
MRI->use_nodbg_empty(VLOpDef->getOperand(0).getReg()))
```
And then we can remove the diff in `hasNonZeroAVL`
https://github.com/llvm/llvm-project/pull/65934
More information about the llvm-commits
mailing list