-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow element extraction/insertion intrinsics to be used in constexpr #159753 #161302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2878,6 +2878,60 @@ static bool interp__builtin_x86_insert_subvector(InterpState &S, CodePtr OpPC, | |
| return true; | ||
| } | ||
|
|
||
| static bool interp__builtin_vec_ext(InterpState &S, CodePtr OpPC, | ||
| const CallExpr *Call, unsigned ID) { | ||
| assert(Call->getNumArgs() == 2); | ||
|
|
||
| APSInt ImmAPS = popToAPSInt(S, Call->getArg(1)); | ||
| const Pointer &Vec = S.Stk.pop<Pointer>(); | ||
| if (!Vec.getFieldDesc()->isPrimitiveArray()) | ||
| return false; | ||
|
|
||
| unsigned NumElts = Vec.getNumElems(); | ||
| unsigned Index = static_cast<unsigned>(ImmAPS.getZExtValue() & (NumElts - 1)); | ||
|
|
||
| switch (ID) { | ||
|
||
| case X86::BI__builtin_ia32_vec_ext_v4sf: | ||
| S.Stk.push<Floating>(Vec.elem<Floating>(Index)); | ||
| return true; | ||
| default: { | ||
| PrimType ElemPT = Vec.getFieldDesc()->getPrimType(); | ||
| INT_TYPE_SWITCH_NO_BOOL(ElemPT, { | ||
| APSInt V = Vec.elem<T>(Index).toAPSInt(); | ||
| pushInteger(S, V, Call->getType()); | ||
| }); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC, | ||
| const CallExpr *Call, unsigned ID) { | ||
| assert(Call->getNumArgs() == 3); | ||
|
|
||
| APSInt ImmAPS = popToAPSInt(S, Call->getArg(2)); | ||
| APSInt ValAPS = popToAPSInt(S, Call->getArg(1)); | ||
|
|
||
| const Pointer &Base = S.Stk.pop<Pointer>(); | ||
| if (!Base.getFieldDesc()->isPrimitiveArray()) | ||
| return false; | ||
|
|
||
| const Pointer &Dst = S.Stk.peek<Pointer>(); | ||
|
|
||
| unsigned NumElts = Base.getNumElems(); | ||
AdityaC4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| unsigned Index = static_cast<unsigned>(ImmAPS.getZExtValue() & (NumElts - 1)); | ||
|
|
||
| PrimType ElemPT = Base.getFieldDesc()->getPrimType(); | ||
| INT_TYPE_SWITCH_NO_BOOL(ElemPT, { | ||
| for (unsigned I = 0; I != NumElts; ++I) | ||
| Dst.elem<T>(I) = Base.elem<T>(I); | ||
| Dst.elem<T>(Index) = static_cast<T>(ValAPS); | ||
| }); | ||
|
|
||
| Dst.initializeAllElements(); | ||
| return true; | ||
| } | ||
|
|
||
| bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, | ||
| uint32_t BuiltinID) { | ||
| if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID)) | ||
|
|
@@ -3686,6 +3740,29 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, | |
| case X86::BI__builtin_ia32_insert128i256: | ||
| return interp__builtin_x86_insert_subvector(S, OpPC, Call, BuiltinID); | ||
|
|
||
| case X86::BI__builtin_ia32_vec_ext_v4hi: | ||
| case X86::BI__builtin_ia32_vec_ext_v16qi: | ||
| case X86::BI__builtin_ia32_vec_ext_v8hi: | ||
| case X86::BI__builtin_ia32_vec_ext_v4si: | ||
| case X86::BI__builtin_ia32_vec_ext_v2di: | ||
| case X86::BI__builtin_ia32_vec_ext_v32qi: | ||
| case X86::BI__builtin_ia32_vec_ext_v16hi: | ||
| case X86::BI__builtin_ia32_vec_ext_v8si: | ||
| case X86::BI__builtin_ia32_vec_ext_v4di: | ||
| case X86::BI__builtin_ia32_vec_ext_v4sf: | ||
| return interp__builtin_vec_ext(S, OpPC, Call, BuiltinID); | ||
|
|
||
| case X86::BI__builtin_ia32_vec_set_v4hi: | ||
| case X86::BI__builtin_ia32_vec_set_v16qi: | ||
| case X86::BI__builtin_ia32_vec_set_v8hi: | ||
| case X86::BI__builtin_ia32_vec_set_v4si: | ||
| case X86::BI__builtin_ia32_vec_set_v2di: | ||
| case X86::BI__builtin_ia32_vec_set_v32qi: | ||
| case X86::BI__builtin_ia32_vec_set_v16hi: | ||
| case X86::BI__builtin_ia32_vec_set_v8si: | ||
| case X86::BI__builtin_ia32_vec_set_v4di: | ||
| return interp__builtin_vec_set(S, OpPC, Call, BuiltinID); | ||
|
|
||
| default: | ||
| S.FFDiag(S.Current->getLocation(OpPC), | ||
| diag::note_invalid_subexpr_in_const_expr) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.