================ @@ -2817,6 +2817,82 @@ static bool interp__builtin_select(InterpState &S, CodePtr OpPC, return true; } +static bool interp__builtin_elementwise_fsh(InterpState &S, CodePtr OpPC, + const CallExpr *Call, + unsigned BuiltinID) { + assert(Call->getNumArgs() == 3); + + const QualType &Arg1Type = Call->getArg(0)->getType(); + const QualType &Arg2Type = Call->getArg(1)->getType(); + const QualType &Arg3Type = Call->getArg(2)->getType(); + + // Non-vector integer types. + if (!Arg1Type->isVectorType()) { + assert(!Arg2Type->isVectorType()); + assert(!Arg3Type->isVectorType()); + const APSInt &Shift = popToAPSInt( + S.Stk, *S.getContext().classify(Call->getArg(2)->getType())); + const APSInt &Lo = popToAPSInt( + S.Stk, *S.getContext().classify(Call->getArg(1)->getType())); + const APSInt &Hi = popToAPSInt( + S.Stk, *S.getContext().classify(Call->getArg(0)->getType())); + APSInt Result; + if (BuiltinID == Builtin::BI__builtin_elementwise_fshl) { + Result = APSInt(llvm::APIntOps::fshl(Hi, Lo, Shift), Hi.isUnsigned()); + } else if (BuiltinID == Builtin::BI__builtin_elementwise_fshr) { + Result = APSInt(llvm::APIntOps::fshr(Hi, Lo, Shift), Hi.isUnsigned()); + } else { + llvm_unreachable("Wrong builtin ID"); + } + pushInteger(S, Result, Call->getType()); + return true; + } + + // Vector type. + assert(Arg1Type->isVectorType() && Arg2Type->isVectorType() && + Arg3Type->isVectorType()); + + const VectorType *VecT = Arg1Type->castAs<VectorType>(); + const PrimType &ElemT = *S.getContext().classify(VecT->getElementType()); + unsigned NumElems = VecT->getNumElements(); + + assert(VecT->getElementType() == + Arg2Type->castAs<VectorType>()->getElementType() && + VecT->getElementType() == + Arg3Type->castAs<VectorType>()->getElementType()); ---------------- ckoparkar wrote:
These types are not considered equal much before constexpr evaluation: ``` typedef const short vector4cshort __attribute__((__vector_size__(8))); typedef short vector4short __attribute__((__vector_size__(8))); ``` ``` error: arguments are of different types ('vector4cshort' (vector of 4 'const short' values) vs 'vector4short' (vector of 4 'short' values)) 25 | constexpr auto chk = __builtin_elementwise_fshl(x,y,z); | ^ ``` Do you think I should still add these assertions to the current interpreter? https://github.com/llvm/llvm-project/pull/153572 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits