[llvm] [RISCV] Allow coalesceVSETVLIs to move an LI if it allows a vsetvli to be mutated. (PR #190287)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 19:56:59 PDT 2026


================
@@ -769,8 +773,22 @@ bool RISCVInsertVSETVLI::canMutatePriorConfig(
     if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
       VNInfo *VNI = getVNInfoFromReg(AVL.getReg(), MI, LIS);
       VNInfo *PrevVNI = getVNInfoFromReg(AVL.getReg(), PrevMI, LIS);
-      if (!VNI || !PrevVNI || VNI != PrevVNI)
-        return false;
+      if (!VNI || !PrevVNI || VNI != PrevVNI) {
+        // If the AVL is defined by a load immediate instruction (ADDI x0, imm),
+        // it can be moved earlier since it has no register dependencies.
+        if (!AVL.getReg().isVirtual())
+          return false;
+
+        MachineInstr *DefMI = MRI->getUniqueVRegDef(AVL.getReg());
+        if (!DefMI || DefMI->getOpcode() != RISCV::ADDI ||
----------------
wangpc-pp wrote:

We should have a helper function to match ADDI for loading immediate?

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


More information about the llvm-commits mailing list