-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[JIT] Fold some bitwise operations to vpternlog #91227
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 all commits
23a2341
bda0f04
0525e21
e5e38ff
83dd601
26bc5a3
8cde9e2
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 |
---|---|---|
|
@@ -1662,6 +1662,82 @@ GenTree* Lowering::LowerHWIntrinsic(GenTreeHWIntrinsic* node) | |
LowerFusedMultiplyAdd(node); | ||
break; | ||
|
||
case NI_SSE_And: | ||
case NI_SSE2_And: | ||
case NI_AVX_And: | ||
case NI_AVX2_And: | ||
case NI_AVX512F_And: | ||
case NI_AVX512DQ_And: | ||
case NI_SSE_Or: | ||
case NI_SSE2_Or: | ||
case NI_AVX_Or: | ||
case NI_AVX2_Or: | ||
case NI_AVX512F_Or: | ||
case NI_AVX512DQ_Or: | ||
case NI_SSE_Xor: | ||
case NI_SSE2_Xor: | ||
case NI_AVX_Xor: | ||
case NI_AVX2_Xor: | ||
case NI_AVX512F_Xor: | ||
case NI_AVX512DQ_Xor: | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any concerns around this becoming out of sync from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this list, we have the intrinsics that can be folded into ternary logic, while ANDNOT related intrinsics cannot be folded currently. On the other hand, I could leave some comments there to specify this issue, if this is the better way to make thing more clear. |
||
{ | ||
tannergooding marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (!comp->IsBaselineVector512IsaSupportedOpportunistically()) | ||
{ | ||
break; | ||
} | ||
GenTree* op1 = node->Op(1); | ||
GenTree* op2 = node->Op(2); | ||
|
||
LIR::Use use; | ||
if (BlockRange().TryGetUse(node, &use)) | ||
{ | ||
// search for structure like: | ||
/* | ||
/- A | ||
+- B | ||
t1 = binary logical op1 | ||
|
||
/- C | ||
+- t1 | ||
t2 = binary logical op2 | ||
*/ | ||
GenTree* second = use.User(); | ||
if (!second->OperIs(GT_HWINTRINSIC) || !second->AsHWIntrinsic()->OperIsBitwiseHWIntrinsic()) | ||
{ | ||
break; | ||
} | ||
|
||
if (second->AsHWIntrinsic()->HWOperGet() == GT_AND_NOT) | ||
{ | ||
// currently ANDNOT logic cannot be optimized by the ternary node. | ||
break; | ||
} | ||
GenTree* op3 = second->AsHWIntrinsic()->Op(1) == node ? second->AsHWIntrinsic()->Op(2) | ||
: second->AsHWIntrinsic()->Op(1); | ||
GenTree* control = comp->gtNewIconNode(node->GetTernaryControlByte(second->AsHWIntrinsic())); | ||
CorInfoType simdBaseJitType = node->GetSimdBaseJitType(); | ||
unsigned simdSize = node->GetSimdSize(); | ||
var_types simdType = Compiler::getSIMDTypeForSize(simdSize); | ||
GenTree* ternaryNode = | ||
comp->gtNewSimdTernaryLogicNode(simdType, op1, op2, op3, control, simdBaseJitType, simdSize); | ||
BlockRange().InsertBefore(second, control, ternaryNode); | ||
LIR::Use finalRes; | ||
if (BlockRange().TryGetUse(second, &finalRes)) | ||
{ | ||
finalRes.ReplaceWith(ternaryNode); | ||
} | ||
else | ||
{ | ||
ternaryNode->SetUnusedValue(); | ||
} | ||
GenTree* next = node->gtNext; | ||
BlockRange().Remove(node); | ||
BlockRange().Remove(second); | ||
return next; | ||
} | ||
break; | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
|
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.
We need to either include the
{ return GT_OR; }
as part of theifdef
-or- more ideally we add the relevant: