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

Allow gtFoldExprSpecial to handle side effects #103382

Merged
merged 2 commits into from
Jun 13, 2024

Conversation

tannergooding
Copy link
Member

@tannergooding tannergooding commented Jun 12, 2024

This just updates, as per the title, gtFoldExprSpecial to allow handling of side effects rather than skipping them.

As part of that, it turns out we weren't tracking GT_RET_EXPR as side effecting, so if gtNodeHasSideEffects was used before the inlining pass and them getting replaced with the result or the original call, then we could have dropped them thinking they were non side effecting. So I ensured we check if the underlying call was side effecting and report based on that instead.

Not many diffs, but a small TP improvement.

@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 12, 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 force-pushed the fold-int branch 3 times, most recently from b449a29 to 960870a Compare June 13, 2024 01:23
@tannergooding
Copy link
Member Author

CC. @dotnet/jit-contrib for review

Comment on lines +16921 to +16929
GenTree* potentialCall = tree;

if (potentialCall->OperIs(GT_RET_EXPR))
{
// We need to preserve return expressions where the underlying call
// has side effects. Otherwise early folding can result in us dropping
// the call.
potentialCall = potentialCall->AsRetExpr()->gtInlineCandidate;
}
Copy link
Member Author

@tannergooding tannergooding Jun 13, 2024

Choose a reason for hiding this comment

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

To comment on this fix a bit more...

gtNodeHasSideEffects is trying to see if it really has side effects or is just marked such because some child node has side effects

It's mainly used as part of gtExtractSideEffList which is trying to build a list of all the real side effects
throwing away anything that isn't itself directly side effecting
i.e. since ADD(call, cns) would be marked as CALL due to propagating side effect flags up through the parent and therefore we want to just save the call in the produced comma, not the add or cns

so it was just missing the fact that GT_RET_EXPR is technically a call itself, just a placeholder until the latter IR transforms take place
which is relevant since the inliner, if it fails, actually removes the block containing the call assuming that GT_RET_EXPR will replace itself with the call
but, we'd have dropped the GT_RET_EXPR as non side effecting if it happened too early (such as happens for gtFoldExprSpecial since it happens as part of normal IL importation and evaluation)

@tannergooding tannergooding merged commit daf6cdc into dotnet:main Jun 13, 2024
105 of 107 checks passed
@tannergooding tannergooding deleted the fold-int branch June 13, 2024 21:20
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 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.

2 participants