-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
#78303 Add transformation ~v1 & v2 to VectorXxx.AndNot(v1, v2) #81993
Changes from 7 commits
4f32df9
66b4ab0
28b09d4
a1ae670
2f0e1a8
56e1bea
94f1ba7
a5a1b44
c24f97b
13835fb
fe39bf6
db3c51f
afc4cfc
3e8805f
5318946
bec1de3
dc6b52e
f8f3912
b34199e
1ae64af
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 |
---|---|---|
|
@@ -10870,6 +10870,97 @@ GenTree* Compiler::fgOptimizeHWIntrinsic(GenTreeHWIntrinsic* node) | |
return node; | ||
} | ||
|
||
#if defined(TARGET_XARCH) || defined(TARGET_ARM64) | ||
|
||
#if defined(TARGET_XARCH) | ||
case NI_SSE_And: | ||
case NI_SSE2_And: | ||
case NI_AVX_And: | ||
case NI_AVX2_And: | ||
#elif defined(TARGET_ARM64) | ||
case NI_AdvSimd_And: | ||
#endif | ||
{ | ||
assert(node->GetOperandCount() == 2); | ||
|
||
GenTree* op1 = node->Op(1); | ||
GenTree* op2 = node->Op(2); | ||
GenTree* lhs = nullptr; | ||
GenTree* rhs = nullptr; | ||
GenTreeHWIntrinsic* inner_hw = nullptr; | ||
|
||
// Transforms ~v1 & v2 to VectorXxx.AndNot(v1, v2) | ||
if (op1->OperIs(GT_HWINTRINSIC)) | ||
{ | ||
GenTreeHWIntrinsic* xor_hw = op1->AsHWIntrinsic(); | ||
switch (xor_hw->GetHWIntrinsicId()) | ||
{ | ||
#if defined(TARGET_XARCH) || defined(TARGET_ARM64) | ||
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. This is unnecessary, you're already in a larger identical That being said, the larger identical |
||
|
||
#if defined(TARGET_XARCH) | ||
case NI_SSE_Xor: | ||
case NI_SSE2_Xor: | ||
case NI_AVX_Xor: | ||
case NI_AVX2_Xor: | ||
#elif defined(TARGET_ARM64) | ||
case NI_AdvSimd_Xor: | ||
#endif | ||
inner_hw = xor_hw; | ||
rhs = op2; | ||
#endif | ||
default: | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// Transforms v2 & (~v1) to VectorXxx.AndNot(v2, v1) | ||
if (op2->OperIs(GT_HWINTRINSIC)) | ||
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. This check is going to miss the opt if we have something like In general you're going to need to match For Arm64, you'll also need to directly check for There are some things we could do to make this overall simpler, but they are slightly more involved changes. 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. I'd, in general, recommend extracting some of this to a helper. For example, you could define something like: genTreeOps GenTreeHWIntrinsic::HWOperGet()
{
switch (GetHWIntrinsicId())
{
#if defined(TARGET_XARCH)
case NI_SSE_And:
case NI_SSE2_And:
case NI_AVX_And:
case NI_AVX2_And:
#elif defined(TARGET_ARM64)
case NI_AdvSimd_And:
#endif
{
return GT_AND;
}
#if defined(TARGET_ARM64)
case NI_AdvSimd_Not:
{
return GT_NOT;
}
#endif
#if defined(TARGET_XARCH)
case NI_SSE_Xor:
case NI_SSE2_Xor:
case NI_AVX_Xor:
case NI_AVX2_Xor:
#elif defined(TARGET_ARM64)
case NI_AdvSimd_Xor:
#endif
{
return GT_XOR;
}
// TODO: Handle other cases
default:
{
return GT_NONE;
}
}
} Such a helper allows you to instead switch over the switch (node->HWOperGet())
{
case GT_AND:
{
GenTree* op1 = node->Op(1);
GenTree* op2 = node->Op(2);
GenTree* lhs = nullptr;
GenTree* rhs = nullptr;
if (op1->OperIsHWIntrinsic())
{
// Try handle: ~op1 & op2
GenTreeHWIntrinsic* hw = op1->AsHWIntrinsic();
genTreeOps hwOper = hw->HWOperGet();
if (hwOper == GT_NOT)
{
lhs = op2;
rhs = op1;
}
else if (op1Oper == GT_XOR)
{
GenTree* hwOp1 = hw->Op(1);
GenTree* hwOp2 = hw->Op(2);
if (hwOp1->IsVectorAllBitsSet())
{
lhs = op2;
rhs = hwOp2;
}
else if (hwOp2->IsVectorAllBitsSet())
{
lhs = op2;
rhs = hwOp1;
}
}
}
if ((lhs == nullptr) && op2->OperIsHWIntrinsic())
{
// Try handle: op1 & ~op2
GenTreeHWIntrinsic* hw = op2->AsHWIntrinsic();
genTreeOps hwOper = hw->HWOperGet();
if (hwOper == GT_NOT)
{
lhs = op1;
rhs = op2;
}
else if (op1Oper == GT_XOR)
{
GenTree* hwOp1 = hw->Op(1);
GenTree* hwOp2 = hw->Op(2);
if (hwOp1->IsVectorAllBitsSet())
{
lhs = op1;
rhs = hwOp2;
}
else if (hwOp2->IsVectorAllBitsSet())
{
lhs = op1;
rhs = hwOp1;
}
}
}
if (lhs == nullptr)
{
break;
}
GenTree* andnNode = gtNewSimdBinOpNode(GT_AND_NOT, simdType, lhs, rhs, simdBaseJitType, simdSize, true);
DEBUG_DESTROY_NODE(node);
INDEBUG(andnNode->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);
return andnNode;
}
default:
{
break;
}
} You could of course also extract the 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. Longer term, I think we may want to introduce a "fake" We may also want to normalize cases like |
||
{ | ||
GenTreeHWIntrinsic* xor_hw = op2->AsHWIntrinsic(); | ||
switch (xor_hw->GetHWIntrinsicId()) | ||
{ | ||
#if defined(TARGET_XARCH) || defined(TARGET_ARM64) | ||
|
||
#if defined(TARGET_XARCH) | ||
case NI_SSE_Xor: | ||
case NI_SSE2_Xor: | ||
case NI_AVX_Xor: | ||
case NI_AVX2_Xor: | ||
#elif defined(TARGET_ARM64) | ||
case NI_AdvSimd_Xor: | ||
#endif | ||
inner_hw = xor_hw; | ||
rhs = op1; | ||
#endif | ||
default: | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if ((inner_hw == nullptr) || (!inner_hw->Op(2)->IsVectorAllBitsSet())) | ||
{ | ||
return node; | ||
} | ||
|
||
var_types simdType = node->TypeGet(); | ||
CorInfoType simdBaseJitType = node->GetSimdBaseJitType(); | ||
unsigned int simdSize = node->GetSimdSize(); | ||
|
||
lhs = inner_hw->Op(1); | ||
|
||
GenTree* andnNode = gtNewSimdBinOpNode(GT_AND_NOT, simdType, lhs, rhs, simdBaseJitType, simdSize, true); | ||
|
||
DEBUG_DESTROY_NODE(node); | ||
|
||
INDEBUG(andnNode->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED); | ||
|
||
return andnNode; | ||
} | ||
#endif | ||
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.
What about Vector128/256_And and AdvSimd ?
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.
Vector64/128/256_And
don't exist outside ofimport
at the moment so they don't need to be handled.AdvSimd
should be since we want parity between xarch and arm.