-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[X86][Clang] Add AVX512 Integer Comparison Intrinsics for constexpr Evaluation #164026
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
dbcb924
[X86][Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - …
sskzakaria fec68e4
build error
sskzakaria ee703e0
fixed argument order
sskzakaria 3b6e186
moved the type switch into the loop body
sskzakaria c3cdc21
format
sskzakaria 151e23b
removing repeated elem(ElemNum).toAPSInt() calls to top of the loop
sskzakaria e96b79b
Apply clang-format
sskzakaria 4895fd9
Revert "Apply clang-format"
sskzakaria b8b4c35
Reducing size of TYPE_SWITCH macro expansion
sskzakaria 69ca76f
changed constexpr tests to used varied values
sskzakaria d84d68c
Reduce type switch size in interp__builtin_cmp_mask
sskzakaria 5aeb4e4
minor changes
sskzakaria f65d516
clang format
sskzakaria 63a8621
Merge branch 'main' into constexpr_cmp
sskzakaria a7b7aa7
Merge branch 'main' into constexpr_cmp
sskzakaria 827aee4
Update clang/lib/AST/ByteCode/InterpBuiltin.cpp
sskzakaria 897d74d
Update clang/lib/AST/ExprConstant.cpp
sskzakaria 897b66a
clang format
sskzakaria c71415a
Update clang/lib/AST/ExprConstant.cpp
sskzakaria ee5c46c
Merge branch 'main' into constexpr_cmp
sskzakaria c5c2ef4
Merge branch 'main' into constexpr_cmp
RKSimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3101,6 +3101,62 @@ static bool interp__builtin_vec_set(InterpState &S, CodePtr OpPC, | |
| return true; | ||
| } | ||
|
|
||
| static bool interp__builtin_cmp_mask(InterpState &S, CodePtr OpPC, | ||
| const CallExpr *Call, unsigned ID, | ||
| bool IsUnsigned) { | ||
| assert(Call->getNumArgs() == 4); | ||
|
|
||
| APSInt Mask = popToAPSInt(S, Call->getArg(3)); | ||
| APSInt Opcode = popToAPSInt(S, Call->getArg(2)); | ||
| const Pointer &RHS = S.Stk.pop<Pointer>(); | ||
| const Pointer &LHS = S.Stk.pop<Pointer>(); | ||
|
|
||
| assert(LHS.getNumElems() == RHS.getNumElems()); | ||
|
|
||
| APInt RetMask = APInt::getZero(LHS.getNumElems()); | ||
| unsigned VectorLen = LHS.getNumElems(); | ||
| PrimType ElemT = LHS.getFieldDesc()->getPrimType(); | ||
|
|
||
| for (unsigned ElemNum = 0; ElemNum < VectorLen; ++ElemNum) { | ||
| INT_TYPE_SWITCH_NO_BOOL(ElemT, { | ||
| const APSInt &A = LHS.elem<T>(ElemNum).toAPSInt(); | ||
| const APSInt &B = RHS.elem<T>(ElemNum).toAPSInt(); | ||
| bool Result = false; | ||
| switch (Opcode.getExtValue() & 0x7) { | ||
|
||
| case 0x00: // _MM_CMPINT_EQ | ||
| Result = (A == B); | ||
| break; | ||
| case 0x01: // _MM_CMPINT_LT | ||
| Result = IsUnsigned ? A.ult(B) : A.slt(B); | ||
| break; | ||
| case 0x02: // _MM_CMPINT_LE | ||
| Result = IsUnsigned ? A.ule(B) : A.sle(B); | ||
| break; | ||
| case 0x03: // _MM_CMPINT_FALSE | ||
| Result = false; | ||
| break; | ||
| case 0x04: // _MM_CMPINT_NE | ||
| Result = (A != B); | ||
| break; | ||
| case 0x05: // _MM_CMPINT_NLT (>=) | ||
| Result = IsUnsigned ? A.uge(B) : A.sge(B); | ||
| break; | ||
| case 0x06: // _MM_CMPINT_NLE (>) | ||
| Result = IsUnsigned ? A.ugt(B) : A.sgt(B); | ||
| break; | ||
| case 0x07: // _MM_CMPINT_TRUE | ||
| Result = true; | ||
| break; | ||
| } | ||
|
|
||
| RetMask.setBitVal(ElemNum, Mask[ElemNum] && Result); | ||
| }); | ||
| } | ||
|
|
||
| pushInteger(S, RetMask, Call->getType()); | ||
| return true; | ||
| } | ||
|
|
||
| static bool interp__builtin_ia32_vpconflict(InterpState &S, CodePtr OpPC, | ||
| const CallExpr *Call) { | ||
| assert(Call->getNumArgs() == 1); | ||
|
|
@@ -4141,6 +4197,36 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call, | |
| case X86::BI__builtin_ia32_vec_set_v4di: | ||
| return interp__builtin_vec_set(S, OpPC, Call, BuiltinID); | ||
|
|
||
| case X86::BI__builtin_ia32_cmpb128_mask: | ||
| case X86::BI__builtin_ia32_cmpw128_mask: | ||
| case X86::BI__builtin_ia32_cmpd128_mask: | ||
| case X86::BI__builtin_ia32_cmpq128_mask: | ||
| case X86::BI__builtin_ia32_cmpb256_mask: | ||
| case X86::BI__builtin_ia32_cmpw256_mask: | ||
| case X86::BI__builtin_ia32_cmpd256_mask: | ||
| case X86::BI__builtin_ia32_cmpq256_mask: | ||
| case X86::BI__builtin_ia32_cmpb512_mask: | ||
| case X86::BI__builtin_ia32_cmpw512_mask: | ||
| case X86::BI__builtin_ia32_cmpd512_mask: | ||
| case X86::BI__builtin_ia32_cmpq512_mask: | ||
| return interp__builtin_cmp_mask(S, OpPC, Call, BuiltinID, | ||
| /*IsUnsigned=*/false); | ||
|
|
||
| case X86::BI__builtin_ia32_ucmpb128_mask: | ||
| case X86::BI__builtin_ia32_ucmpw128_mask: | ||
| case X86::BI__builtin_ia32_ucmpd128_mask: | ||
| case X86::BI__builtin_ia32_ucmpq128_mask: | ||
| case X86::BI__builtin_ia32_ucmpb256_mask: | ||
| case X86::BI__builtin_ia32_ucmpw256_mask: | ||
| case X86::BI__builtin_ia32_ucmpd256_mask: | ||
| case X86::BI__builtin_ia32_ucmpq256_mask: | ||
| case X86::BI__builtin_ia32_ucmpb512_mask: | ||
| case X86::BI__builtin_ia32_ucmpw512_mask: | ||
| case X86::BI__builtin_ia32_ucmpd512_mask: | ||
| case X86::BI__builtin_ia32_ucmpq512_mask: | ||
| return interp__builtin_cmp_mask(S, OpPC, Call, BuiltinID, | ||
| /*IsUnsigned=*/true); | ||
|
|
||
| default: | ||
| S.FFDiag(S.Current->getLocation(OpPC), | ||
| diag::note_invalid_subexpr_in_const_expr) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interp__builtin_cmp_mask -> interp__builtin_ia32_cmp_mask