[llvm-branch-commits] [llvm] [RISCV] Schedule RVV instructions with compatible type first (PR #95924)

Luke Lau via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 7 23:03:53 PST 2026


================
@@ -13,6 +13,62 @@ using namespace llvm;
 
 #define DEBUG_TYPE "riscv-prera-sched-strategy"
 
+static cl::opt<bool> EnableVTypeSchedHeuristic(
+    "riscv-enable-vtype-sched-heuristic", cl::init(false), cl::Hidden,
+    cl::desc("Enable scheduling RVV instructions based on vtype heuristic "
+             "(pick instruction with compatible vtype first)"));
+
+bool RISCVPreRAMachineSchedStrategy::enableVTypeSchedHeuristic() const {
+  if (EnableVTypeSchedHeuristic.getNumOccurrences() > 0)
+    return EnableVTypeSchedHeuristic;
+  return ST->enableVTypeSchedHeuristic();
+}
+
+RISCV::VSETVLIInfo
+RISCVPreRAMachineSchedStrategy::getVSETVLIInfo(const MachineInstr *MI) const {
+  unsigned TSFlags = MI->getDesc().TSFlags;
+  if (!RISCVII::hasSEWOp(TSFlags))
+    return RISCV::VSETVLIInfo();
+  return VIA.computeInfoForInstr(*MI);
+}
+
+bool RISCVPreRAMachineSchedStrategy::tryVType(RISCV::VSETVLIInfo TryVType,
+                                              RISCV::VSETVLIInfo CandVtype,
+                                              SchedCandidate &TryCand,
+                                              SchedCandidate &Cand,
+                                              CandReason Reason) const {
+  // Do not compare the vtype changes between top and bottom
+  // boundary.
+  if (Cand.AtTop != TryCand.AtTop)
+    return false;
+
+  // Try Cand first.
+  // We prefer the top node as it is straightforward from the perspective of
+  // vtype dataflow.
+  if (CandVtype.isValid() && TopVType.isValid() && Cand.AtTop &&
+      CandVtype == TopVType)
+    return true;
+
+  if (CandVtype.isValid() && BottomVType.isValid() && !Cand.AtTop &&
+      CandVtype == BottomVType)
----------------
lukel97 wrote:

I agree, in that case I think this patch description should be renamed to `Schedule RVV instructions with compatible vtype and vl first`, and VType in this function to CandInfo/BottomInfo etc.

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


More information about the llvm-branch-commits mailing list