[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:34:07 PDT 2026


================
@@ -2275,20 +2306,21 @@ static void computeKnownBitsFromOperator(const Operator *I,
       case Intrinsic::riscv_vsetvli:
       case Intrinsic::riscv_vsetvlimax: {
         bool HasAVL = II->getIntrinsicID() == Intrinsic::riscv_vsetvli;
-        const ConstantRange Range = getVScaleRange(II->getFunction(), BitWidth);
-        uint64_t SEW = RISCVVType::decodeVSEW(
-            cast<ConstantInt>(II->getArgOperand(HasAVL))->getZExtValue());
-        RISCVVType::VLMUL VLMUL = static_cast<RISCVVType::VLMUL>(
-            cast<ConstantInt>(II->getArgOperand(1 + HasAVL))->getZExtValue());
-        uint64_t MaxVLEN =
-            Range.getUnsignedMax().getZExtValue() * RISCV::RVVBitsPerBlock;
-        uint64_t MaxVL = MaxVLEN / RISCVVType::getSEWLMULRatio(SEW, VLMUL);
+        ConstantRange Range = getRISCVVSetVLMaxRange(*II, HasAVL);
+        if (Range.isFullSet())
+          break;
+        uint64_t MaxVL = Range.getUnsignedMax().getZExtValue();
 
         // Result of vsetvli must be not larger than AVL.
         if (HasAVL)
           if (auto *CI = dyn_cast<ConstantInt>(II->getArgOperand(0)))
             MaxVL = std::min(MaxVL, CI->getZExtValue());
 
+        if (MaxVL == 0) {
+          Known.setAllZero();
+          break;
+        }
----------------
lukel97 wrote:

Can we move this into getRISCVVSetVLMaxRange and then also handle riscv_vsetvli in getRangeForIntrinsic?

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


More information about the llvm-commits mailing list