aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorAmy Kwan <amy.kwan1@ibm.com>2020-09-23 17:14:24 -0500
committerAmy Kwan <amy.kwan1@ibm.com>2020-09-23 22:55:25 -0500
commit6b136b19cbe4e96adea63b75f1f2f76ec25c708e (patch)
tree00b49e4cd8108b8c98c0396753817415b80e1c7d /clang/lib/Sema/SemaChecking.cpp
parentd1aa143aa84e20a8cdef24a0b5ccf70941884534 (diff)
downloadllvm-6b136b19cbe4e96adea63b75f1f2f76ec25c708e.zip
llvm-6b136b19cbe4e96adea63b75f1f2f76ec25c708e.tar.gz
llvm-6b136b19cbe4e96adea63b75f1f2f76ec25c708e.tar.bz2
[Power10] Implement custom codegen for the vec_replace_elt and vec_replace_unaligned builtins.
This patch implements custom codegen for the vec_replace_elt and vec_replace_unaligned builtins. These builtins map to the @llvm.ppc.altivec.vinsw and @llvm.ppc.altivec.vinsd intrinsics depending on the arguments. The main motivation for doing custom codegen for these intrinsics is because there are float and double versions of the builtin. Normally, the converting the float to an integer would be done via fptoui in the IR. This is incorrect as fptoui truncates the value and we must ensure the value is not truncated. Therefore, we provide custom codegen to utilize bitcast instead as bitcasts do not truncate. Differential Revision: https://reviews.llvm.org/D83500
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f2b70be..eeb3222 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2570,6 +2570,17 @@ static bool isValidBPFPreserveFieldInfoArg(Expr *Arg) {
dyn_cast<ArraySubscriptExpr>(Arg->IgnoreParens()));
}
+static bool isEltOfVectorTy(ASTContext &Context, CallExpr *Call, Sema &S,
+ QualType VectorTy, QualType EltTy) {
+ QualType VectorEltTy = VectorTy->castAs<VectorType>()->getElementType();
+ if (!Context.hasSameType(VectorEltTy, EltTy)) {
+ S.Diag(Call->getBeginLoc(), diag::err_typecheck_call_different_arg_types)
+ << Call->getSourceRange() << VectorEltTy << EltTy;
+ return false;
+ }
+ return true;
+}
+
static bool isValidBPFPreserveTypeInfoArg(Expr *Arg) {
QualType ArgType = Arg->getType();
if (ArgType->getAsPlaceholderType())
@@ -3222,6 +3233,14 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
return SemaVSXCheck(TheCall);
case PPC::BI__builtin_altivec_vgnb:
return SemaBuiltinConstantArgRange(TheCall, 1, 2, 7);
+ case PPC::BI__builtin_altivec_vec_replace_elt:
+ case PPC::BI__builtin_altivec_vec_replace_unaligned: {
+ QualType VecTy = TheCall->getArg(0)->getType();
+ QualType EltTy = TheCall->getArg(1)->getType();
+ unsigned Width = Context.getIntWidth(EltTy);
+ return SemaBuiltinConstantArgRange(TheCall, 2, 0, Width == 32 ? 12 : 8) ||
+ !isEltOfVectorTy(Context, TheCall, *this, VecTy, EltTy);
+ }
case PPC::BI__builtin_vsx_xxeval:
return SemaBuiltinConstantArgRange(TheCall, 3, 0, 255);
case PPC::BI__builtin_altivec_vsldbi: