[llvm] [RISCV] Handle recurrences in RISCVVLOptimizer (PR #151285)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 00:09:07 PDT 2025


================
@@ -30,6 +40,27 @@ using namespace llvm;
 
 namespace {
 
+/// Wrapper around MachineOperand that defaults to immediate 0.
+struct DemandedVL {
+  MachineOperand VL;
+  DemandedVL() : VL(MachineOperand::CreateImm(0)) {}
+  DemandedVL(MachineOperand VL) : VL(VL) {}
+  static DemandedVL vlmax() {
+    return DemandedVL(MachineOperand::CreateImm(RISCV::VLMaxSentinel));
+  }
+  bool operator!=(const DemandedVL &Other) const {
+    return !VL.isIdenticalTo(Other.VL);
+  }
+};
+
+static DemandedVL max(const DemandedVL &LHS, const DemandedVL &RHS) {
+  if (RISCV::isVLKnownLE(LHS.VL, RHS.VL))
+    return RHS;
+  if (RISCV::isVLKnownLE(RHS.VL, LHS.VL))
+    return LHS;
+  return DemandedVL::vlmax();
----------------
lukel97 wrote:

When we have two VLs that are both virtual registers, in which case we can't discern which one is known to be larger. So we just give up and conservatively demand everything.

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


More information about the llvm-commits mailing list