Skip to content

Enable constant folding in Tier0 - #82412

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:tier0-constant-folding
Feb 24, 2023
Merged

Enable constant folding in Tier0#82412
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:tier0-constant-folding

Conversation

@EgorBo

@EgorBoEgorBo commented Feb 20, 2023

Copy link
Copy Markdown
Member

From what I see so far that we should mainly focus on two things in Tier0 (except for debug-friendly code):

  1. Emit less basic-block/class probes counters due to cache contention in multi-thread env
  2. Remove dead branches early because most of the time in Tier0 we spend inside VM calls (resolve tokens, type loadings, etc) so the more code we remove the less we touch VM. For instance, here are first seconds of Paint.NET's launch forced to stay in tier0:

image

(purple for methods with CEEInfo:: - VM stuff)

Example of a code this PR improves in Tier0:

staticvoidMain(){if(typeof(int)==typeof(float))Console.WriteLine();}

was:

; Assembly listing for method P:Main()G_M1402_IG01: 55pushrbp 4883EC20 subrsp,32 488D6C2420 learbp,[rsp+20H]G_M1402_IG02:  33C0 xoreax,eax 85C0 testeax,eax7406je SHORT G_M1402_IG03 FF15FA7B7800 call[System.Console:WriteLine()]G_M1402_IG03: 90nopG_M1402_IG04:  4883C420 addrsp,32 5D poprbp C3 ret; Total bytes of code 29

now:

; Assembly listing for method P:Main()G_M1402_IG01: 55pushrbp 488BEC movrbp,rspG_M1402_IG02: G_M1402_IG03:  5D poprbp C3 ret; Total bytes of code 6

Two notes:

  1. SplitCriticalEdges used to assume edges couldn't be folded away unless we optimize and instrument
  2. CLFLG_CONSTANTFOLD is removed as not useful - there are tons of places where it's not checked anyway

@ghostghost assigned EgorBoFeb 20, 2023
@EgorBoEgorBo mentioned this pull request Feb 20, 2023
23 tasks
@EgorBo

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-coreclr outerloop, runtime-coreclr pgo, runtime-coreclr libraries-pgo

@EgorBo
EgorBo marked this pull request as ready for review February 21, 2023 10:02
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

Comment threadsrc/coreclr/jit/morph.cpp Outdated
@EgorBo

Copy link
Copy Markdown
MemberAuthor

@AndyAyersMS@jakobbotsch PTAL


// NOTE: MinOpts() is always true for Tier0 so we have to check explicit flags instead.
// To be fixed in https://github.com/dotnet/runtime/pull/77465
const bool tier0opts = !opts.compDbgCode && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have an explicit Tier0 flag, why not check this?

tree = gtFoldExpr(tree);
if (opts.OptimizationEnabled())
{
tree = gtFoldExpr(tree);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the gtFold... seems like we should have a consistent pattern we use -- either the caller or the callee should check if optimizations are enabled, but not both?

Maybe this is covered in your opt levels PR?

@AndyAyersMS

Copy link
Copy Markdown
Member

Linking to #9120.

@EgorBo

Copy link
Copy Markdown
MemberAuthor

@AndyAyersMS thanks! Merging to make it to Preview2. I'll indeed clean up the checks in #77465

@EgorBo
EgorBo merged commit 13a80ca into dotnet:mainFeb 24, 2023
@EgorBo
EgorBo deleted the tier0-constant-folding branch February 24, 2023 11:27
@EgorBo

Copy link
Copy Markdown
MemberAuthor

Failure is #82397

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@EgorBo@AndyAyersMS@jakobbotsch