[llvm] [llubi] Implement experimental vector intrinsics (PR #206899)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 07:15:59 PDT 2026
================
@@ -1629,6 +1725,145 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
case Intrinsic::experimental_noalias_scope_decl:
// FIXME: Not implemented yet. Currently it acts as a noop.
return AnyValue();
+ case Intrinsic::experimental_cttz_elts: {
+ auto *IsZeroPoisonC = cast<ConstantInt>(CB.getArgOperand(1));
+ const bool IsZeroPoison = IsZeroPoisonC->isOne();
+
+ const auto &Vec = Args[0].asAggregate();
+ const unsigned RetBW = RetTy->getIntegerBitWidth();
+
+ if (APInt::getMaxValue(RetBW).ult(Vec.size()))
+ return AnyValue::poison();
+
+ uint64_t Count = 0;
+ for (const AnyValue &V : Vec) {
+ if (V.isPoison())
+ return AnyValue::poison();
+ if (!V.asInteger().isZero())
+ break;
+ ++Count;
+ }
+
+ if (Count == Vec.size() && IsZeroPoison)
+ return AnyValue::poison();
+ return APInt(RetBW, Count);
+ }
+ case Intrinsic::experimental_get_vector_length: {
+ auto *VFC = cast<ConstantInt>(CB.getArgOperand(1));
+ auto *ScalableC = cast<ConstantInt>(CB.getArgOperand(2));
+
+ if (Args[0].isPoison())
+ return AnyValue::poison();
+
+ const APInt &Cnt = Args[0].asInteger();
+ const uint64_t VF = VFC->getZExtValue();
+ const bool Scalable = ScalableC->isOne();
+
+ const uint64_t MaxLanes =
+ Scalable ? Ctx.getEVL(ElementCount::getScalable(VF)) : VF;
+
+ uint64_t Res = 0;
----------------
lukel97 wrote:
No, but does it matter if other users of the value can have side effects? e.g. does llubi need to consider if the store might be UB, depending on what get.vector.length returns?
```
%x = call i32 get.vector.length(...)
%gep = getelementptr ..., i32 %x
store i32 0, ptr %gep
```
https://github.com/llvm/llvm-project/pull/206899
More information about the llvm-commits
mailing list