[llvm] [RISCV] coalesce between VSETVLI and SF_VSETTNT (PR #203438)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 22:45:30 PDT 2026
================
@@ -933,6 +936,98 @@ void RISCVInsertVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) const {
}
}
+// When twiden != 0, LMUL, tail policy, and mask policy from the user are
+// ignored. The tail policy and mask policy are always treated as agnostic. The
+// normal RVV instruction will ignore the twiden parameter. This observation
+// could allow the RVV instruction and xsfmm instruction to share the same
+// configuration instruction.
+//
+// We need to make sure the AVL, SEW, and AltFmt is same between VSETVL and
+// VSETVLTN.
+//
+// For example:
+//
+// %avl = SETTM or SETTK
+// ...
+// VSETVL %avl, type1
+// VSETVLTNT %avl, type2
+//
+// ->
+//
+// %avl = SETTM or SETTK
+// ...
+// VSETVLTNT %avl, type2
+//
+bool RISCVInsertVSETVLI::canMutatePriorConfigWithTWiden(
+ const MachineInstr &PrevMI, const MachineInstr &MI) const {
+
+ if (PrevMI.getOpcode() != RISCV::PseudoVSETVLI)
+ return false;
+
+ if (MI.getOpcode() != RISCV::PseudoSF_VSETTNT)
+ return false;
+
+ auto PrevInfo = VIA.getInfoForVSETVLI(PrevMI);
+ auto CurrInfo = VIA.getInfoForVSETVLI(MI);
+
+ auto AVLReg = CurrInfo.getAVLReg();
+
+ auto *AVLRegDefMI = MRI->getUniqueVRegDef(AVLReg);
+
+ if (!AVLRegDefMI)
+ return false;
+
+ if (!RISCVInstrInfo::isXSfmmVectorConfigTMTKInstr(*AVLRegDefMI))
+ return false;
+
+ auto AVLRegDefMIInfo = VIA.computeInfoForInstr(*AVLRegDefMI);
+ if (AVLRegDefMIInfo.getTWiden() != CurrInfo.getTWiden())
+ return false;
+
+ if (AVLRegDefMIInfo.getSEW() != PrevInfo.getSEW())
+ return false;
+
+ // CurrInfo twiden != 0, so TailAgnostic and MaskAgnostic bit default to 1
+ if (!PrevInfo.getTailAgnostic() || !PrevInfo.getMaskAgnostic())
+ return false;
+
+ if (!PrevInfo.hasSameAVL(CurrInfo))
+ return false;
+
+ if (PrevInfo.getSEW() != CurrInfo.getSEW())
+ return false;
+
+ if (PrevInfo.getAltFmt() != CurrInfo.getAltFmt())
+ return false;
+
----------------
topperc wrote:
> Right! I missed that avl is from XSfmmVectorConfigTMTKInstr.
but should the LMUL check of PrevMI be at least min(8/KMAX, 8/TWIDEN, ceil(ETE/EVE)) instead of just checking at least 8/KMAX?
We don't have access to ETE. That's a runtime value of the implementation so we can't check that at compile time. What we need to ensure is that the LMUL of the vsetvli isn't smaller than that min produces. If we check that the LMUL is at least 8/KMAX then we know it's at least as large as the min produces.
https://github.com/llvm/llvm-project/pull/203438
More information about the llvm-commits
mailing list