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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 22:18:44 PDT 2026


================
@@ -769,8 +773,20 @@ 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 || !RISCVInstrInfo::isLoadImmediate(*DefMI) ||
+            DefMI->getParent() != PrevMI.getParent()) {
----------------
lukel97 wrote:

Can we allow mutating the config when `DefMI->getParent() != PrevMI.getParent()` are different? PrevMI and MI need to be in the same block IIUC. So if DefMI is in a different block it will still dominate without needing to be moved

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


More information about the llvm-commits mailing list