Skip to content
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

Arm64/Sve: Handle ConvertTo* APIs properly #103876

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/coreclr/jit/hwintrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,18 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
break;
}
}
#elif defined(TARGET_ARM64)
switch (intrinsic)
{
case NI_Sve_ConvertToInt32:
case NI_Sve_ConvertToUInt32:
// Save the base type of return SIMD. It is used to contain this intrinsic inside
// ConditionalSelect.
retNode->AsHWIntrinsic()->SetAuxiliaryJitType(getBaseJitTypeOfSIMDType(sig->retTypeSigClass));
break;
default:
break;
}
#endif // TARGET_XARCH

break;
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/jit/hwintrinsiccodegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,20 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node)
{
assert(!instrIsRMW);

// Special handling for ConvertTo* APIs
// Just need to change the opt here.
switch (intrinEmbMask.id)
{
case NI_Sve_ConvertToInt32:
case NI_Sve_ConvertToUInt32:
{
opt = intrinEmbMask.baseType == TYP_DOUBLE ? INS_OPTS_D_TO_S : INS_OPTS_SCALABLE_S;
break;
}
default:
break;
}

if (targetReg != falseReg)
{
// If targetReg is not the same as `falseReg` then need to move
Expand Down
35 changes: 28 additions & 7 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3347,14 +3347,35 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node)
// Handle op2
if (op2->OperIsHWIntrinsic())
{
uint32_t maskSize = genTypeSize(node->GetSimdBaseType());
uint32_t operSize = genTypeSize(op2->AsHWIntrinsic()->GetSimdBaseType());

if ((maskSize == operSize) && IsInvariantInRange(op2, node) &&
op2->isEmbeddedMaskingCompatibleHWIntrinsic())
if (IsInvariantInRange(op2, node) && op2->isEmbeddedMaskingCompatibleHWIntrinsic())
{
MakeSrcContained(node, op2);
op2->MakeEmbMaskOp();
uint32_t maskSize = genTypeSize(node->GetSimdBaseType());
uint32_t operSize = genTypeSize(op2->AsHWIntrinsic()->GetSimdBaseType());
if (maskSize == operSize)
{
// If the size of baseType of operation matches that of maskType, then contain
// the operation
MakeSrcContained(node, op2);
op2->MakeEmbMaskOp();
}
else
{
// Else check if this operation has an auxiliary type that matches the
// mask size.
GenTreeHWIntrinsic* embOp = op2->AsHWIntrinsic();

// For now, make sure that we get here only for intrinsics that we are
// sure about to rely on auxiliary type's size.
assert((embOp->GetHWIntrinsicId() == NI_Sve_ConvertToInt32) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you intend for this assert to go away once @ebepho implements ConvertToInt64, or should we keep checking for intrinsics with different base/return types? If the latter, I wonder if we ought to add a flag for these types of intrinsics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, we will update the assert, but may be later, we might consider adding a flag. For now, I want to see if there are more intrinsic categories that falls under this.

(embOp->GetHWIntrinsicId() == NI_Sve_ConvertToUInt32));

uint32_t auxSize = genTypeSize(embOp->GetAuxiliaryType());
if (maskSize == auxSize)
{
MakeSrcContained(node, op2);
op2->MakeEmbMaskOp();
}
}
}
}

Expand Down
Loading