[llvm] [InstSimplify] Consider vscale_range for get active lane mask (PR #160073)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 07:55:29 PDT 2025


================
@@ -6474,10 +6474,27 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
                                      const CallBase *Call) {
   unsigned BitWidth = ReturnType->getScalarSizeInBits();
   switch (IID) {
-  case Intrinsic::get_active_lane_mask:
+  case Intrinsic::get_active_lane_mask: {
     if (match(Op1, m_Zero()))
       return ConstantInt::getFalse(ReturnType);
+
+    const Function *F = Call->getFunction();
+    auto ScalableTy = dyn_cast<ScalableVectorType>(ReturnType);
+    if (ScalableTy && F->hasFnAttribute(Attribute::VScaleRange)) {
+      Attribute Attr = F->getFnAttribute(Attribute::VScaleRange);
+      std::optional<unsigned> VScaleMax = Attr.getVScaleRangeMax();
+      if (!VScaleMax)
+        break;
+      unsigned MaxPossibleMaskElements =
+          ScalableTy->getMinNumElements() * (*VScaleMax);
----------------
nikic wrote:

Is there a risk of overflow here?

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


More information about the llvm-commits mailing list