[llvm] [llubi] Implement experimental vector intrinsics (PR #206899)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 07:22:29 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;
----------------
dtcxzyw wrote:
> does llubi need to consider if the store might be UB, depending on what get.vector.length returns?
Yes. I mean the external side effect (e.g., immediate UB/IO/return value of main).
If the source IR runs successfully and the target IR after LoopVectorize/LoopIdiomVectorize triggers UB, it should be a miscompilation bug.
https://github.com/llvm/llvm-project/pull/206899
More information about the llvm-commits
mailing list