Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JIT: Use faster write barriers when we know the target address is on the heap#97953

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
EgorBo merged 9 commits intodotnet:mainfromEgorBo:assertprop-wb-fix-3
Feb 8, 2024

Conversation

@EgorBo
Copy link
Member

@EgorBoEgorBo commentedFeb 5, 2024
edited
Loading

Closes#97534

TL;DR: JIT has an optimization that tries to simplify/remove write barriers, but that optimization happens too late to rely on VN/SSA/Assertions, so CSE can easily ruin it by moving addresses or values to locals and forcing that opt to give up and use the checked write barrier. This PR assists that optimization from assertion prop (#97901 did it for nongc objects as values for such indirs), Example:

publicstructSlot{publicobjectItem;publicintSequenceNumber;}staticvoidTest(Slot[]arr,objecto){arr[0].Item=o;arr[0].SequenceNumber=1;}

Codegen forTest:

; Method LdtokenRepro:Test(Slot[],System.Object) (FullOpts)G_M35662_IG01:  ;; offset=0x0000       push     rbx       sub      rsp, 32G_M35662_IG02:  ;; offset=0x0005       cmp      dword ptr [rcx+0x08], 0       jbe      SHORT G_M35662_IG04       lea      rbx, bword ptr [rcx+0x10]       mov      rcx, rbx-      call     CORINFO_HELP_CHECKED_ASSIGN_REF+      call     CORINFO_HELP_ASSIGN_REF       mov      dword ptr [rbx+0x08], 1G_M35662_IG03:  ;; offset=0x001E       add      rsp, 32       pop      rbx       ret      G_M35662_IG04:  ;; offset=0x0024       call     CORINFO_HELP_RNGCHKFAIL       int3     ; Total bytes of code: 42

@ghostghost added the area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labelFeb 5, 2024
@ghostghost assignedEgorBoFeb 5, 2024
@ghost
Copy link

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

Issue Details

Closes#97534

TL;DR: JIT has an optimization that tries to simplify/remove write barriers, but that optimization happens to late to rely on VN/SSA/Assertions, so CSE can easily ruin it by moving addresses or values to locals and forcing that opt to give up and use the checked write barrier. This PR assists that optimization from assertion prop, Example:

publicstructSlot{publicobjectItem;publicintSequenceNumber;}staticvoidTest(Slot[]arr,objecto){arr[0].Item=o;arr[0].SequenceNumber=1;}

Codegen forTest:

; Method LdtokenRepro:Test(Slot[],System.Object) (FullOpts)G_M35662_IG01:  ;; offset=0x0000       push     rbx       sub      rsp, 32G_M35662_IG02:  ;; offset=0x0005       cmp      dword ptr [rcx+0x08], 0       jbe      SHORT G_M35662_IG04       lea      rbx, bword ptr [rcx+0x10]       mov      rcx, rbx-      call     CORINFO_HELP_CHECKED_ASSIGN_REF+      call     CORINFO_HELP_ASSIGN_REF       mov      dword ptr [rbx+0x08], 1G_M35662_IG03:  ;; offset=0x001E       add      rsp, 32       pop      rbx       ret      G_M35662_IG04:  ;; offset=0x0024       call     CORINFO_HELP_RNGCHKFAIL       int3     ; Total bytes of code: 42
Author:EgorBo
Assignees:EgorBo
Labels:

area-CodeGen-coreclr

Milestone:-

@EgorBoEgorBo marked this pull request as ready for reviewFebruary 5, 2024 12:51
@EgorBo
Copy link
MemberAuthor

@AndyAyersMS@jakobbotsch cc@SingleAccretion @dotnet/jit-contrib PTAL.Diffs. Diffs aren't too big becauseCORINFO_HELP_CHECKED_ASSIGN_REF ->CORINFO_HELP_ASSIGN_REF change has 0 size diff, but should improve perf since the latter doesn't need to check whether pointer targets heap or not (two comparisons). Most size diffs come fromPtrToLoc ->NoWritebarrier. A small TP regression due to GetVNFunc in a loop (the regression was much bigger before I minimized it), but, hopefully, faster write barriers are worth it.

Closes#97534

@EgorBo
Copy link
MemberAuthor

@MihuBot

@EgorBo
Copy link
MemberAuthor

ping@AndyAyersMS - I presume it should help you with CSE work sinceCORINFO_HELP_ASSIGN_REF andCORINFO_HELP_CHECKED_ASSIGN_REF have the same asm and PerfScore, so CSE changes migth silently regress them.

I analyzed jit-diff on top of BCL and this PR removed ~2400 checked write barriers.

kunalspathak reacted with hooray emoji

if (arg1Type != GCInfo::WriteBarrierForm::WBF_BarrierUnknown)
{
return arg1Type;
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

NOTE: this has an assumption that "addressOfLocal + addressOfHeap" is UB

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Made it a bit more conservative (it didn't affect diffs) by requiring the 2nd argument to be a non-handle constant. So, if we see address being GT_ADD(op1, op2) and one of the arguments is either address-of-local or address-within-heap, the other argument must be a non-handle constant.

Copy link
Contributor

@kunalspathakkunalspathak left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Copy link
Member

@AndyAyersMSAndyAyersMS left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this.

We could / should have perf score reflect the cost of helper calls (likewise with gtCostEx).

@EgorBo
Copy link
MemberAuthor

We could / should have perf score reflect the cost of helper calls (likewise with gtCostEx).

I agree, I assume currently all unknown calls have the same cost (assuming same arguments)? Do we want to make all helpers cheaper than unknown calls or more expensive? I presume this could result in some diffs

@EgorBo
Copy link
MemberAuthor

Failures are known + PR passed all checks before adding debug JITDUMPs

@EgorBoEgorBo merged commitcd8057f intodotnet:mainFeb 8, 2024
@EgorBoEgorBo deleted the assertprop-wb-fix-3 branchFebruary 8, 2024 14:42
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 10, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@AndyAyersMSAndyAyersMSAndyAyersMS approved these changes

+1 more reviewer

@kunalspathakkunalspathakkunalspathak approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@EgorBoEgorBo

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

JIT: CSE of an address computation can result in a write barrier change

3 participants

@EgorBo@AndyAyersMS@kunalspathak

[8]ページ先頭

©2009-2025 Movatter.jp