Skip to content

Track dependently-promoted fields when struct local is no longer referenced. - #37280

Merged
erozenfeld merged 1 commit into
dotnet:masterfrom
erozenfeld:FollowUp36918
Jun 9, 2020
Merged

Track dependently-promoted fields when struct local is no longer referenced.#37280
erozenfeld merged 1 commit into
dotnet:masterfrom
erozenfeld:FollowUp36918

Conversation

@erozenfeld

Copy link
Copy Markdown
Contributor

This is a follow-up to #36918. It addresses one of the examples in #1007
where we remove a struct zero initialization but fail to clean up a dead
field assignment.

The change is not to mark a dependently promoted field as untracked
if we know that the struct local is no longer referenced.

I also addressed a couple of late cosmetic review comments from #36918.

No diffs in framework and benchmarks.

@Dotnet-GitSync-BotDotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 1, 2020
@erozenfeld

Copy link
Copy Markdown
ContributorAuthor

Example from #1007:

Example 4:

usingSystem.Runtime.InteropServices;publicclassC{[StructLayout(LayoutKind.Sequential,Size=24)]publicstructBuffer{publiculongField1;publiculongField2;publicuintField3;}publicvoidM(){varbuf=newBuffer();buf.Field1=2;}}

Diffs after #36918 (optimization to remove zero inits):

G_M25775_IG01:
4883EC18 sub rsp, 24
- C5F877 vzeroupper
C5D857E4 vxorps xmm4, xmm4
C5F97F2424 vmovdqa xmmword ptr [rsp], xmm4
33C0 xor rax, rax
4889442410 mov qword ptr [rsp+10H], rax
;; bbWeight=1 PerfScore 3.83
G_M25775_IG02:
- 33C0 xor eax, eax- C5F857C0 vxorps xmm0, xmm0- C5FA7F0424 vmovdqu xmmword ptr [rsp], xmm0- 4889442410 mov qword ptr [rsp+10H], rax
48C7042402000000 mov qword ptr [rsp], 2
G_M25775_IG03:
4883C418 add rsp, 24
C3 ret
-; Total bytes of code 52, prolog size 23, PerfScore 14.27, (MethodHash=0c929b50) for method C:M()+; Total bytes of code 33, prolog size 20, PerfScore 8.58, (MethodHash=0c929b50) for method C:M()

Diffs after this change:

G_M25775_IG01:
- 4883EC18 sub rsp, 24- C5D857E4 vxorps xmm4, xmm4- C5F97F2424 vmovdqa xmmword ptr [rsp], xmm4- 33C0 xor rax, rax- 4889442410 mov qword ptr [rsp+10H], rax
G_M25775_IG02:
- 48C7042402000000 mov qword ptr [rsp], 2
G_M25775_IG03:
- 4883C418 add rsp, 24
C3 ret
-; Total bytes of code 33, prolog size 20, PerfScore 8.58, (MethodHash=0c929b50) for method C:M()+; Total bytes of code 1, prolog size 0, PerfScore 1.10, (MethodHash=0c929b50) for method C:M()

@erozenfeld

Copy link
Copy Markdown
ContributorAuthor

@dotnet/jit-contrib @CarolEidt PTAL

@erozenfeld
erozenfeld requested a review from CarolEidtJune 1, 2020 22:30
This is a follow-up to dotnet#36918. It addresses one of the examples in dotnet#1007
where we remove a struct zero initialization but fail to clean up a dead
field assignment.
The change is not to mark a dependently promoted field as untracked
if we know that the struct local is no longer referenced.
I also addressed a couple of late cosmetic review comments from dotnet#36918.
No diffs in framework and benchmarks.
@erozenfelderozenfeld changed the title Track promoted fields when struct local is no longer referenced.Track dependently-promoted fields when struct local is no longer referenced.Jun 8, 2020
@erozenfeld

Copy link
Copy Markdown
ContributorAuthor

I pushed a change that fixes Linux arm test failures.
@CarolEidt @dotnet/jit-contrib PTAL

@CarolEidtCarolEidt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, with just one question for curiosity's sake.

}
// Fields of dependently promoted structs may be tracked. We shouldn't set lvMustInit on them since
// the whole parent struct will be initialized; however, lvLiveInOutOfHndlr should be set on them
// as appropriate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the field is dependently promoted (i.e. the whole struct is forced to live on the stack), then do we still need to mark them as lvLiveInOutOfHndlr since they'll always be defined/used to/from the stack?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

With this change we may enregister a field of a dependently promoted struct if the struct is no longer used. See the change in lclvars.cpp: we don't set lvaSetVarDoNotEnregister on such fields.

@erozenfeld
erozenfeld merged commit ee17aa6 into dotnet:masterJun 9, 2020
CarolEidt added a commit to CarolEidt/runtime that referenced this pull request Jun 10, 2020
@JulieLeeMSFTJulieLeeMSFT added this to the 5.0.0 milestone Jun 19, 2020
@ghostghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR 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

@erozenfeld@CarolEidt@Dotnet-GitSync-Bot@JulieLeeMSFT