[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 08:09:08 PDT 2025
================
@@ -2266,6 +2266,89 @@ static bool BuiltinCountZeroBitsGeneric(Sema &S, CallExpr *TheCall) {
return false;
}
+static bool CheckMaskedBuiltinArgs(Sema &S, Expr *MaskArg, Expr *PtrArg,
+ unsigned Pos) {
+ QualType MaskTy = MaskArg->getType();
+ if (!MaskTy->isExtVectorBoolType()) {
+ S.Diag(MaskArg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+ << 1 << /* vector of */ 4 << /* booleans */ 6 << /* no fp */ 0
+ << MaskTy;
+ return true;
+ }
+
+ QualType PtrTy = PtrArg->getType();
+ if (!PtrTy->isPointerType() || !PtrTy->getPointeeType()->isVectorType()) {
+ S.Diag(PtrArg->getExprLoc(), diag::err_vec_masked_load_store_ptr)
+ << Pos << "pointer to vector";
+ return true;
+}
+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);
+ if (CheckMaskedBuiltinArgs(S, MaskArg, PtrArg, 2))
+ return ExprError();
+
+ QualType MaskTy = MaskArg->getType();
+ QualType PtrTy = PtrArg->getType();
+ QualType PointeeTy = PtrTy->getPointeeType();
+ const VectorType *MaskVecTy = MaskTy->getAs<VectorType>();
+ const VectorType *DataVecTy = PointeeTy->getAs<VectorType>();
+ if (MaskVecTy->getNumElements() != DataVecTy->getNumElements())
+ return ExprError(
----------------
erichkeane wrote:
Huh, TIL...
https://github.com/llvm/llvm-project/pull/154464
More information about the cfe-commits
mailing list