Skip to content

JIT: Allow cloning addresses even before initobj - #79341

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:fix-42354
Dec 8, 2022
Merged

JIT: Allow cloning addresses even before initobj#79341
jakobbotsch merged 1 commit into
dotnet:mainfrom
jakobbotsch:fix-42354

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Dec 7, 2022

Copy link
Copy Markdown
Member

Roslyn emits ldloca + dup + initobj when initializing structs. Normally we clone address trees instead of creating a local for them (which will address expose the local), but we treat this initobj pattern specially.

Remove this special treatment. It means we sometimes end up with slightly larger code because we no longer have a register with the address in it (could potentially be fixed by CSE), but avoiding the address exposure seems like the right trade off to me.

Fix #42354
Fix #57055

Roslyn emits ldloca + dup + initobj when initializing structs. Normally
we clone address trees instead of creating a local for them (which will
address expose the local), but we treat this initobj pattern specially.

Remove this special treatment. It means we sometimes end up with
slightly larger code because we no longer have a register with the
address in it (could potentially be fixed by CSE), but avoiding the
address exposure seems like the right trade off to me.

Fix dotnet#42354
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 7, 2022
@ghost ghost assigned jakobbotsch Dec 7, 2022
@ghost

ghost commented Dec 7, 2022

Copy link
Copy Markdown

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

Issue Details

Roslyn emits ldloca + dup + initobj when initializing structs. Normally we clone address trees instead of creating a local for them (which will address expose the local), but we treat this initobj pattern specially.

Remove this special treatment. It means we sometimes end up with slightly larger code because we no longer have a register with the address in it (could potentially be fixed by CSE), but avoiding the address exposure seems like the right trade off to me.

Fix #42354

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo

EgorBo commented Dec 7, 2022

Copy link
Copy Markdown
Member

Was it me who added it? I think I was trying to minimize number of size regressions in the diffs but didn't analyze them so LGTM assuming diffs are perf improvements

@jakobbotsch

Copy link
Copy Markdown
Member Author

Was it me who added it? I think I was trying to minimize number of size regressions in the diffs but didn't analyze them so LGTM assuming diffs are perf improvements

Yes, looks like it was (although it's possible the two fixed issues also needed #72714 before they actually were fixed)

All the regressions I spot checked looked like:

-       lea      rcx, bword ptr [rsp+30H]
-       ; byrRegs +[rcx]
-       mov      byte  ptr [rcx], 0
-       mov      bword ptr [rsp+20H], rcx
-       ; byr arg write
+       mov      byte  ptr [rsp+30H], 0
+       lea      rcx, [rsp+30H]
+       mov      qword ptr [rsp+20H], rcx
        mov      rcx, rdi
        ; gcrRegs +[rcx]
-       ; byrRegs -[rcx]

So we just get a slightly larger instruction for accessing some stack memory, which I doubt affects performance significantly. On the other hand, not having the local address exposed means we sometimes are able to completely eliminate them after inlining and other optimizations, so that seems worth it to me (and fixes those two issues).

@jakobbotsch

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr superpmi-replay

@azure-pipelines

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

@jakobbotsch
jakobbotsch merged commit eb8d5f7 into dotnet:main Dec 8, 2022
@jakobbotsch
jakobbotsch deleted the fix-42354 branch December 8, 2022 09:11
@ghost ghost locked as resolved and limited conversation to collaborators Jan 7, 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.

Unnecessary stack spilling for struct instant property access JIT: Poor codegen when calling an instance method on a temporary, unused struct

2 participants