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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 23:11:30 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()) {
----------------
topperc wrote:

Wouldn't that have been covered by the existing VNInfo checks? I'm not really sure it's possible for DefMI and PrevMI to be different here. What I do know is that `LiveIntervals::handleMove` doesn't handle moves across basic blocks so I was being extra causious.

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


More information about the llvm-commits mailing list