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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 23 03:18:14 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);
----------------
david-arm wrote:

I guess a 64-bit value should be sufficient here since both `getMinNumElements` and `getVScaleRangeMax` return 32-bit values.

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


More information about the llvm-commits mailing list