[llvm-branch-commits] [RISCV] Attach VLMAX range attribute for vsetvli/vsetvlimax in InstCombine (PR #218652)

Pengcheng Wang via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 25 03:03:50 PDT 2026


https://github.com/wangpc-pp created https://github.com/llvm/llvm-project/pull/218652

Attach a range return attribute describing the result when InstCombine visits
a `riscv_vsetvli/vsetvlimax` intrinsic. `VLMAX = VLEN * LMUL / SEW`, and the
subtarget's real VLEN bounds give a known range for VLMAX.

  * vsetvlimax sets vl = VLMAX, so the result spans the whole VLMAX range.
  * vsetvli sets vl = f(AVL, VLMAX) with 0 <= vl <= min(AVL, VLMAX). The
    result equals AVL only when AVL cannot exceed the smallest possible VLMAX;
    for any larger (or non-constant) AVL, vl may shrink below VLMAX all the way
    down to 0, so only the VLMAX-derived upper bound is sound. We must not
    claim a VLMAX lower bound in that case.

Materializing the range as an attribute lets the generic value analyses
(computeKnownBits, computeConstantRange, isKnownNonZero) reason about the
result through CallBase::getRange() without target-specific knowledge, and
uses the precise per-subtarget VLEN instead of the architectural maximum.

The IR verifier guarantees these intrinsics have an XLen result and constant
VSEW/VLMUL operands encoding a valid SEW/LMUL pair, so decoding the vtype here
needs no defensive validation and cannot hit the decodeVSEW / decodeVLMUL
asserts.

Assisted-by: TRAE CLI (Opus 4.8)
Co-authored-by: TRAE CLI <traecli at bytedance.com>





More information about the llvm-branch-commits mailing list