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

Share more of the TYP_MASK handling and support rewriting TYP_MASK operands in rationalization #103288

Merged
merged 6 commits into from
Jun 12, 2024

Conversation

tannergooding
Copy link
Member

This resolves the issue introduced by #102702 which was discovered in #103094 (comment).

The bug was missed in the initial PR as the Arm64 handling for mask <-> vector conversions was a bit different from Xarch, and it wasn't expected to be able to encounter nodes in such a shape.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 11, 2024
@DragosDanielBoia
Copy link
Contributor

@dotnet-policy-service rerun

@kunalspathak
Copy link
Member

@dotnet/arm64-contrib FYI

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this.

@@ -99,6 +99,23 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use,
// for intrinsics that get rewritten back to user calls
assert(!operand->OperIsFieldList());

if (varTypeIsMask(operand->TypeGet()))
{
#if defined(FEATURE_HW_INTRINSICS)
Copy link
Member

Choose a reason for hiding this comment

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

Instead wrap the if-condition in #ifdef FEATURE_MASKED_HW_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.

TYP_MASK and a lot of the surrounding support isn't under that feature switch.

If we were to centralize everything under that feature switch, I think it should be a separate PR. However, I'm also not convinced we need that as we didn't set any such flag up for XARCH.

Copy link
Member

Choose a reason for hiding this comment

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

Have a separate PR is fine for me, but do we even see TYP_MASK if it is not FEATURED_HW_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.

I don't believe we do today, but that doesn't mean it will never happen. varTypeIsMask returns constant false on unsupported platforms, so this just ensures any future scenarios handle this appropriately and will be optimized out as dead code otherwise.

CorInfoType simdBaseJitType,
unsigned simdSize)
{
assert(varTypeIsMask(type));
Copy link
Contributor

@TIHan TIHan Jun 11, 2024

Choose a reason for hiding this comment

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

Do we need to pass a TYP_MASK for type every time we call gtNewSimdCvtVectorToMaskNode ? Since we only have one TYP_MASK, feels like we could just get rid of this parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's here to support any future expansion desired. For example, it may be important to differentiate mask based on size.

@@ -1657,14 +1657,14 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
// HWInstrinsic requires a mask for op2
if (!varTypeIsMask(op2))
{
retNode->AsHWIntrinsic()->Op(2) = gtNewSimdCvtVectorToMaskNode(retType, op2, simdBaseJitType, simdSize);
retNode->AsHWIntrinsic()->Op(2) = gtNewSimdCvtVectorToMaskNode(TYP_MASK, op2, simdBaseJitType, simdSize);
Copy link
Member

Choose a reason for hiding this comment

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

probably add an assert in gtNewSimdCvtVectorToMaskNode() that type == TYP_MASK?

Copy link
Member Author

Choose a reason for hiding this comment

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

That assert already exists and is what caught the failure.

Copy link
Contributor

@TIHan TIHan left a comment

Choose a reason for hiding this comment

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

LGTM. This will fix the assertions in #103094

@tannergooding tannergooding merged commit 96be3e2 into dotnet:main Jun 12, 2024
112 of 114 checks passed
@tannergooding tannergooding deleted the rewrite-mask branch June 12, 2024 07:01
@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants