Skip to content

Conversation

@BruceForstall
Copy link
Contributor

I noticed that the MSVC compiler wasn't inlining some checks to OptimizationEnabled()/Disabled(), which should be super simple, although it's a small computed value. To help, cache the computed value so no computation need be done when checking it.

I noticed that the MSVC compiler wasn't inlining some checks
to OptimizationEnabled()/Disabled(), which should be super
simple, although it's a small computed value. To help, cache
the computed value so no computation need be done when checking it.
@ghost ghost assigned BruceForstall Jan 20, 2023
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label 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

I noticed that the MSVC compiler wasn't inlining some checks to OptimizationEnabled()/Disabled(), which should be super simple, although it's a small computed value. To help, cache the computed value so no computation need be done when checking it.

Author: BruceForstall
Assignees: BruceForstall
Labels:

area-CodeGen-coreclr

Milestone: -

// If there is nothing next, that means the result is thrown away, so this value is not live.
// However, for minopts or debuggable code, we keep it live to support managed return value debugging.
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.compDbgCode)
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.DbgCode())
Copy link
Member

Choose a reason for hiding this comment

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

!compiler->opts.MinOpts() && !compiler->opts.DbgCode()

This is doing the same thing if (opts.OptimizationsEnabled()) does. Should it just be simplified to that?

// If there is nothing next, that means the result is thrown away, so this value is not live.
// However, for minopts or debuggable code, we keep it live to support managed return value debugging.
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.compDbgCode)
if ((call->gtNext == nullptr) && !compiler->opts.MinOpts() && !compiler->opts.DbgCode())
Copy link
Member

Choose a reason for hiding this comment

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

Same here. This is really just if ((call->gtNext == nullptr) && compiler->opts.OptimizationsEnabled())

bool MinOpts() const
{
assert(compMinOptsIsSet);
compMinOptsIsUsed = true;
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering, what's the general point of this and why do we need to track it as part of the check whether min opts is enabled

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. Shouldn't compMinOptsIsSet sufficient to make sure that we are not calling MinOpts() before it is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once we read the value, we should never try to set it afterwards -- someone has taken a dependency on the value. Like the PhasedVar stuff.

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we just have a check in SetMinOpts to assert we aren't past import or anything?

We should really only be setting it when the compiler is created or in the case we fault and fallback to minopts, right?

Once we've hit import, we're basically guaranteed to have some path that checks it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, but the effect would not be as obvious or direct, and of course, compMinOptsIsUsed is DEBUG-only code.

@EgorBo
Copy link
Member

EgorBo commented Jan 20, 2023

@BruceForstall I actually did this in #77465 that I planned to land this (well, next) week - OptimizationEnabled is a single field load in my PR.

(well, except hiding compDbgCode under a method)

@BruceForstall
Copy link
Contributor Author

Diffs

TP diffs up to -0.10%. Odd small regression on x64 MinOpts collections.

@BruceForstall I actually did this in #77465 that I planned to land this (well, next) week - OptimizationEnabled is a single field load in my PR.

Ok, I'll close this. I was curious what the TP change would be, and it's surprisingly significant (given our SPMI measurement). I presume you maintain that benefit.

@EgorBo
Copy link
Member

EgorBo commented Jan 20, 2023

Yes it was around that. I promise I'll land it coming few days 🙂

@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.

4 participants