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

Fold some expressions early in importer #80888

Merged
merged 5 commits into from
Jan 20, 2023
Merged

Fold some expressions early in importer #80888

merged 5 commits into from
Jan 20, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 20, 2023

No description provided.

@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 Jan 20, 2023
@ghost ghost assigned EgorBo Jan 20, 2023
@ghost
Copy link

ghost commented Jan 20, 2023

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

Issue Details

null

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Jan 20, 2023

@dotnet/jit-contrib single-line change, slightly improves TP and mostly negative diffs.
Size regressions seem to be due to cse, assert prop and branch opts misbehaviors e.g. https://www.diffchecker.com/g6dvRgEN/

TP wins are due to the fact that it now (in some places) removes dead branches earlier than previously and doesn't waste time performing SSA/VN on those, I have a concrete example if you need one.

@EgorBo EgorBo marked this pull request as ready for review January 20, 2023 15:43
// TODO: we might want to only perform gtFoldExprConst here for TP
op1 = gtFoldExpr(impPopStack().val);
op1 = impPopStack().val;
op1 = opts.OptimizationEnabled() ? gtFoldExpr(op1) : op1;
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth having a helper impPopStackAndFoldExpr()?

We can then mark it as forceinline and have it do the two step thing + relevant optimization checks?

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, should we just have foldExpr be a more general part of impPushStack(node)?

We already do explicit gtFoldExpr as part of pushing several node types up, but not more generally.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably? I assume it needs to be justified in other places as in general it could be a TP regression to run gtFoldExpr where it won't fold anything. But in this place it makes sense to do because BRTRUE/BRFALSE are branches + condition so we potentially remove a branch early

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 similar to what we already do for other branches so seems fine.

Doing this more broadly, as Egor says, may not accomplish much other than make the jit slower. But it's probably worth prototyping.

Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

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

Nice diffs!

@AndyAyersMS
Copy link
Member

There are small number of minopts diffs, any idea why?

@EgorBo
Copy link
Member Author

EgorBo commented Jan 20, 2023

There are small number of minopts diffs, any idea why?

Most paths in gtFoldExpr are guarded with opts.OptimizationEnabled() except gtFoldExprConditional - can slap one there as well. Do you mind if I do it separately? We ran an experiment with early out with OptimizationEnabled and it demonstrated nice wins for MinOpts TP but it turns out we first need to make OptimizationEnabled() slightly cheaper than it is now

@AndyAyersMS
Copy link
Member

Do you mind if I do it separately?

That's fine. It makes it a little harder to be confident there are no net minopts diffs, but I suppose it's possible we've been doing opts already we didn't intend to do and so the diffs in the follow-up may be more than just undoing the ones here.

@EgorBo
Copy link
Member Author

EgorBo commented Jan 20, 2023

Do you mind if I do it separately?

That's fine. It makes it a little harder to be confident there are no net minopts diffs, but I suppose it's possible we've been doing opts already we didn't intend to do and so the diffs in the follow-up may be more than just undoing the ones here.

Exactly - we do it in other places as well, a local experiment demonstrated nice wins for early out in gtFoldExrp (up to -0.45%) for MinOpts but first we need to make opts.OptimizationEnabled cheaper

@EgorBo EgorBo merged commit ff12237 into dotnet:main Jan 20, 2023
@EgorBo EgorBo deleted the fold-early branch January 20, 2023 23:54
mdh1418 pushed a commit to mdh1418/runtime that referenced this pull request Jan 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 20, 2023
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.

3 participants