[llvm] [SCCP] Handle llvm.experimental.get.vector.length calls (PR #169527)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 26 20:18:19 PST 2025


================
@@ -2098,6 +2098,38 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
       return (void)mergeInValue(ValueState[II], II,
                                 ValueLatticeElement::getRange(Result));
     }
+    if (II->getIntrinsicID() == Intrinsic::experimental_get_vector_length) {
+      Value *CountArg = II->getArgOperand(0);
+      Value *VF = II->getArgOperand(1);
+      bool Scalable = cast<ConstantInt>(II->getArgOperand(2))->isOne();
+
+      // Computation happens in the larger type.
+      unsigned BitWidth = std::max(CountArg->getType()->getScalarSizeInBits(),
+                                   VF->getType()->getScalarSizeInBits());
+
+      ConstantRange Count = getValueState(CountArg)
+                                .asConstantRange(CountArg->getType(), false)
+                                .zextOrTrunc(BitWidth);
+      ConstantRange MaxLanes = getValueState(VF)
+                                   .asConstantRange(VF->getType(), false)
+                                   .zextOrTrunc(BitWidth);
----------------
dtcxzyw wrote:

```suggestion
                                   .zext(BitWidth);
```

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


More information about the llvm-commits mailing list