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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 24 11:41:03 PDT 2023


================
@@ -1255,6 +1258,12 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
         MachineOperand &VLOp = MI.getOperand(getVLOpNum(MI));
         if (VLOp.isReg()) {
           // Erase the AVL operand from the instruction.
+          if (MachineInstr *MI = MRI->getVRegDef(VLOp.getReg());
+              MI && MI->getOpcode() == RISCV::ADDI &&
----------------
topperc wrote:

Technically ADDI can have a non-registeroperand 1 or a non-immediate operand 2. It's very unlikely to happen since that should only happen with pointers, but someone could do a strange bitcast. We should check isReg() and isImm() before getReg and getImm to be safe.

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


More information about the llvm-commits mailing list