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

Centralize the folding logic for ConditionalSelect and ensure side effects aren't dropped #104175

Merged
merged 5 commits into from
Jun 30, 2024

Conversation

tannergooding
Copy link
Member

This resolves #104116

@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 28, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@tannergooding tannergooding marked this pull request as ready for review June 29, 2024 04:41
@tannergooding
Copy link
Member Author

CC. @dotnet/jit-contrib, this should be ready for review.

There's some decent diffs:

Overall (-17,311 bytes)
MinOpts (-8,835 bytes)
FullOpts (-8,476 bytes)

Where most of this comes from us properly recognizing ~mask and being able to optimize it:

-       vpmovm2d zmm1, k1
-       vpternlogd zmm0, zmm0, zmm1, 85
-       vpmovd2m k1, zmm0
+       knotw    k1, k1

There's, however, a couple small regressions where the not isn't recognized and folded into the vpternlogd since that's not part of the handling today (just and/or/xor are covered):

-       vpcmpeqd xmm2, xmm2, xmm2
-       vpternlogd xmm1, xmm0, xmm2, 86
-       vptest   xmm1, xmm1
+       vpor     xmm0, xmm1, xmm0
+       vpcmpeqd xmm1, xmm1, xmm1
+       vpxor    xmm0, xmm1, xmm0
+       vptest   xmm0, xmm0

I want to handle these separately where I can also fixup the logic to do proper containment support for this case and get the rest of the wins possible here.

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.

Looks good. Added few questions.

break;
}

if (nestedIsScalar)
Copy link
Member

Choose a reason for hiding this comment

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

This is always false so we do not need it or did you forget to set it?

Copy link
Member Author

Choose a reason for hiding this comment

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

This exists as a form of future proofing, its expected that isScalar could be true and we don’t handle that case here

/*
/- A
+- B
t1 = binary logical op1
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure I follow the example in the comment - It is trying to find op1 and op2 has nested opertions basically.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is finding a bitwise operation that contains a nested bitwise operation so they can become a single ternary operation

bool nestedIsScalar = false;
genTreeOps nestedOper = second->AsHWIntrinsic()->HWOperGet(&isScalar);

if (nestedOper == GT_NONE)
Copy link
Member

Choose a reason for hiding this comment

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

don't think we need this condition. It will be taken care by the condition on line 1468 below.

Copy link
Member Author

Choose a reason for hiding this comment

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

The one further down is temporary and will be removed so we can handle other cases such as not, and_not, and other other future binary operations

@tannergooding tannergooding merged commit fcdb6db into dotnet:main Jun 30, 2024
114 checks passed
@tannergooding tannergooding deleted the fold-cndsel branch June 30, 2024 16:28
@github-actions github-actions bot locked and limited conversation to collaborators Jul 31, 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.

Arm64/Sve: Removal of ConditionalSelect's operands when mask is AllFalse/AllTrue
3 participants