[llvm] [RISCV] coalesce between VSETVLI and SF_VSETTNT (PR #203438)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 00:57:55 PDT 2026
================
@@ -933,6 +936,109 @@ 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;
+
+ // The PrevMI's LMUL should be at least 8/KMAX; otherwise, converting it to a
+ // tail-widening version would result in a VLMAX smaller than what AVLRegDefMI
+ // expects, causing the LMUL information from PrevMI to be lost.
+ unsigned LMul;
+ bool Fractional;
+ std::tie(LMul, Fractional) = decodeVLMUL(PrevInfo.getVLMUL());
----------------
lukel97 wrote:
Nit
```suggestion
auto [LMul, Fractional] = decodeVLMUL(PrevInfo.getVLMUL());
```
https://github.com/llvm/llvm-project/pull/203438
More information about the llvm-commits
mailing list