[llvm] [RISCV] Track the value range of vsetvlimax (PR #218313)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 22:19:57 PDT 2026
================
@@ -87,6 +87,37 @@
using namespace llvm;
using namespace llvm::PatternMatch;
+// Return the architectural range for VLMAX. RISC-V defines VLEN in the range
+// [32, 65536], while vscale_range can provide tighter bounds for VLEN >= 64.
+static ConstantRange getRISCVVSetVLMaxRange(const IntrinsicInst &II,
+ unsigned ArgOffset = 0) {
+ unsigned Width = II.getType()->getScalarSizeInBits();
+ constexpr unsigned MinVLen = 32;
+ constexpr unsigned MaxVLen = 65536;
+ ConstantRange VLenRange(APInt(Width, MinVLen), APInt(Width, MaxVLen + 1));
+ if (II.getFunction() &&
+ II.getFunction()->hasFnAttribute(Attribute::VScaleRange)) {
+ ConstantRange VScaleRange = getVScaleRange(II.getFunction(), Width);
+ VScaleRange = VScaleRange.intersectWith(ConstantRange(
+ APInt(Width, 1), APInt(Width, MaxVLen / RISCV::RVVBitsPerBlock + 1)));
+ VLenRange = VScaleRange.multiply(
+ ConstantRange(APInt(Width, RISCV::RVVBitsPerBlock)));
+ }
+
+ auto *VSEW = dyn_cast<ConstantInt>(II.getArgOperand(ArgOffset));
+ auto *VLMULArg = dyn_cast<ConstantInt>(II.getArgOperand(ArgOffset + 1));
+ // These are immarg operands, but keep this helper conservative for malformed
+ // IR rather than asserting while performing generic value analysis.
+ if (!VSEW || !VLMULArg || VSEW->getZExtValue() > 3 ||
+ VLMULArg->getZExtValue() > 7 || VLMULArg->getZExtValue() == 4)
+ return ConstantRange::getFull(Width);
----------------
lukel97 wrote:
I don't think malformed IR can get through here, doesn't the verifier reject it? Probably best to keep the cast and assert
https://github.com/llvm/llvm-project/pull/218313
More information about the llvm-commits
mailing list