[llvm] [RISCV][VLOPT] Compute demanded VLs up front. NFC (PR #124530)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 07:39:28 PST 2025


================
@@ -1230,46 +1233,59 @@ RISCVVLOptimizer::getMinimumVLForUser(MachineOperand &UserOp) {
   // Looking for an immediate or a register VL that isn't X0.
   assert((!VLOp.isReg() || VLOp.getReg() != RISCV::X0) &&
          "Did not expect X0 VL");
+
+  // If we know the demanded VL of UserMI, then we can reduce the VL it
+  // requires.
+  if (DemandedVLs.contains(&UserMI)) {
+    // We can only shrink the demanded VL if the elementwise result doesn't
+    // depend on VL (i.e. not vredsum/viota etc.)
+    // Also conservatively restrict to supported instructions for now.
+    // TODO: Can we remove the isSupportedInstr check?
+    if (!RISCVII::elementsDependOnVL(
+            TII->get(RISCV::getRVVMCOpcode(UserMI.getOpcode())).TSFlags) &&
+        isSupportedInstr(UserMI)) {
----------------
lukel97 wrote:

Yeah, I had just added out of an abundance of caution. I think `!RISCVII::elementsDependOnVL` is enough for correctness.

Actually now that you mention it, we already check for isSupportedInstr before inserting anything into demandedVLs. So I think this isSupportedInstr check is redundant. Should I remove it?

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


More information about the llvm-commits mailing list