Skip to content

Commit e77d682

Browse files
committed
Ensure CndSel handles 64-bit operands where possible
1 parent f71ea56 commit e77d682

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/coreclr/jit/lowerxarch.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,8 +3078,6 @@ GenTree* Lowering::LowerHWIntrinsicCmpOp(GenTreeHWIntrinsic* node, genTreeOps cm
30783078
//
30793079
GenTree* Lowering::LowerHWIntrinsicCndSel(GenTreeHWIntrinsic* node)
30803080
{
3081-
assert(!comp->canUseEvexEncodingDebugOnly());
3082-
30833081
var_types simdType = node->gtType;
30843082
CorInfoType simdBaseJitType = node->GetSimdBaseJitType();
30853083
var_types simdBaseType = node->GetSimdBaseType();
@@ -3102,17 +3100,34 @@ GenTree* Lowering::LowerHWIntrinsicCndSel(GenTreeHWIntrinsic* node)
31023100
// we can optimize the entire conditional select to
31033101
// a single BlendVariable instruction (if supported by the architecture)
31043102

3105-
// TODO-XARCH-AVX512 Use VPBLENDM* and take input directly from K registers if cond is from MoveMaskToVectorSpecial.
31063103
// First, determine if the condition is a per-element mask
31073104
if (op1->OperIsHWIntrinsic() && HWIntrinsicInfo::ReturnsPerElementMask(op1->AsHWIntrinsic()->GetHWIntrinsicId()))
31083105
{
31093106
// Next, determine if the target architecture supports BlendVariable
31103107
NamedIntrinsic blendVariableId = NI_Illegal;
31113108

3112-
// For Vector256 (simdSize == 32), BlendVariable for floats/doubles is available on AVX, whereas other types
3113-
// require AVX2
3114-
if (simdSize == 32)
3109+
bool isOp1CvtMaskToVector = op1->AsHWIntrinsic()->OperIsConvertMaskToVector();
3110+
3111+
if ((simdSize == 64) || isOp1CvtMaskToVector)
31153112
{
3113+
if (isOp1CvtMaskToVector)
3114+
{
3115+
op1 = op1->AsHWIntrinsic()->Op(1);
3116+
}
3117+
else
3118+
{
3119+
op1 = comp->gtNewSimdCvtVectorToMaskNode(TYP_MASK, op1, simdBaseJitType, simdSize);
3120+
BlockRange().InsertBefore(node, op1);
3121+
}
3122+
3123+
assert(op1->TypeGet() == TYP_MASK);
3124+
blendVariableId = NI_EVEX_BlendVariableMask;
3125+
}
3126+
else if (simdSize == 32)
3127+
{
3128+
// For Vector256 (simdSize == 32), BlendVariable for floats/doubles
3129+
// is available on AVX, whereas other types (integrals) require AVX2
3130+
31163131
if (varTypeIsFloating(simdBaseType))
31173132
{
31183133
// This should have already been confirmed
@@ -3124,9 +3139,9 @@ GenTree* Lowering::LowerHWIntrinsicCndSel(GenTreeHWIntrinsic* node)
31243139
blendVariableId = NI_AVX2_BlendVariable;
31253140
}
31263141
}
3127-
// For Vector128, BlendVariable is available on SSE41
31283142
else if (comp->compOpportunisticallyDependsOn(InstructionSet_SSE41))
31293143
{
3144+
// For Vector128, BlendVariable is available on SSE41
31303145
blendVariableId = NI_SSE41_BlendVariable;
31313146
}
31323147

0 commit comments

Comments
 (0)