- Notifications
You must be signed in to change notification settings - Fork5.2k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedFeb 5, 2024
Tagging subscribers to this area:@JulieLeeMSFT,@jakobbotsch Issue DetailsCloses#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 for ; 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
|
EgorBo commentedFeb 5, 2024
@AndyAyersMS@jakobbotsch cc@SingleAccretion @dotnet/jit-contrib PTAL.Diffs. Diffs aren't too big because Closes#97534 |
EgorBo commentedFeb 5, 2024
EgorBo commentedFeb 7, 2024
ping@AndyAyersMS - I presume it should help you with CSE work since I analyzed jit-diff on top of BCL and this PR removed ~2400 checked write barriers. |
| if (arg1Type != GCInfo::WriteBarrierForm::WBF_BarrierUnknown) | ||
| { | ||
| return arg1Type; | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
kunalspathak left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM. Thanks!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
AndyAyersMS left a comment
There was a problem hiding this 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 commentedFeb 8, 2024
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 commentedFeb 8, 2024
Failures are known + PR passed all checks before adding debug JITDUMPs |
Uh oh!
There was an error while loading.Please reload this page.
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:
Codegen for
Test: