[llvm] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 03:19:31 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:

Oh woops, I thought this was inside doLocalPostpass. I guess these are coming from the forwards pass then

https://github.com/llvm/llvm-project/pull/65934


More information about the llvm-commits mailing list