[clang] [Clang] Add builtins for masked vector loads / stores (PR #154464)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 20 06:27:49 PDT 2025
================
@@ -2266,6 +2266,87 @@ static bool BuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
return false;
}
+static ExprResult BuiltinMaskedLoad(Sema &S, CallExpr *TheCall) {
+ if (S.checkArgCount(TheCall, 2))
+ return ExprError();
+
+ Expr *MaskArg = TheCall->getArg(0);
+ Expr *PtrArg = TheCall->getArg(1);
+
+ QualType MaskTy = MaskArg->getType();
+ if (!MaskTy->isExtVectorBoolType())
+ return ExprError(
+ S.Diag(MaskArg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+ << 1 << /* vector of */ 4 << /* booleans */ 6 << /* no fp */ 0
+ << MaskTy);
+
+ QualType PtrTy = PtrArg->getType();
+ if (!PtrTy->isPointerType() || !PtrTy->getPointeeType()->isVectorType())
+ return ExprError(
+ S.Diag(PtrArg->getExprLoc(), diag::err_vec_masked_load_store_ptr)
+ << 2 << "pointer to vector");
+
+ QualType PointeeTy = PtrTy->getPointeeType();
+ const VectorType *MaskVecTy = MaskTy->getAs<VectorType>();
+ const VectorType *DataVecTy = PointeeTy->getAs<VectorType>();
+ if (MaskVecTy->getNumElements() != DataVecTy->getNumElements())
+ return ExprError(
+ S.Diag(TheCall->getBeginLoc(), diag::err_vec_masked_load_store_size)
+ << "__builtin_masked_load" << MaskTy << PointeeTy);
+
+ TheCall->setType(PointeeTy);
+ return TheCall;
+}
+
+static ExprResult BuiltinMaskedStore(Sema &S, CallExpr *TheCall) {
+ if (S.checkArgCount(TheCall, 3))
----------------
erichkeane wrote:
Mask and pointer arg, which is about 2/3 of the fuctions, are the same, right? Seems like a `CheckBuiltinMaskPointerArgs` function cleans this up a bunch, and would, IMO, improve readabilitiy.
https://github.com/llvm/llvm-project/pull/154464
More information about the cfe-commits
mailing list