Skip to content

Conversation

@jakobbotsch
Copy link
Member

Switch to sets when accumulating the memory dependencies found in
VNForMapSelectWork. Otherwise we might duplicate each memory dependency
for every path back to the store that induced it, and there can be an
exponential number of those.

Fix #93342

…lectWork

Switch to sets when accumulating the memory dependencies found in
VNForMapSelectWork. Otherwise we might duplicate each memory dependency
for every path back to the store that induced it, and there can be an
exponential number of those.

Fix dotnet#93342
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 11, 2023
@ghost ghost assigned jakobbotsch Oct 11, 2023
@ghost
Copy link

ghost commented Oct 11, 2023

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

Issue Details

Switch to sets when accumulating the memory dependencies found in
VNForMapSelectWork. Otherwise we might duplicate each memory dependency
for every path back to the store that induced it, and there can be an
exponential number of those.

Fix #93342

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

No diffs

Some odd MinOpts TP diffs that I wouldn't expect, I want to check why tomorrow.

@jakobbotsch jakobbotsch marked this pull request as ready for review October 11, 2023 22:01
Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Changes LGTM, one minor comment nit.

Couldn't the MapSelectWorkCacheEntry hold a SmallValueNumSet too? Or do you think that is not worth it because that set is fixed and array rep is more space efficient?

void ValueNumStore::MapSelectWorkCacheEntry::SetMemoryDependencies(CompAllocator alloc,
ArrayStack<ValueNum>& deps,
unsigned startIndex)
void ValueNumStore::MapSelectWorkCacheEntry::SetMemoryDependencies(Compiler* comp, SmallValueNumSet& set)
Copy link
Member

Choose a reason for hiding this comment

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

Update arg comment just above

@jakobbotsch
Copy link
Member Author

Couldn't the MapSelectWorkCacheEntry hold a SmallValueNumSet too? Or do you think that is not worth it because that set is fixed and array rep is more space efficient?

Ah, yes it can, since we are creating a separate set for every recursive call now. I'll make that change and perhaps shrink the default size a bit depending on the memory overhead.

@jakobbotsch
Copy link
Member Author

Couldn't the MapSelectWorkCacheEntry hold a SmallValueNumSet too? Or do you think that is not worth it because that set is fixed and array rep is more space efficient?

Hmm, it has some significant ish memory overhead (1.3% more VN memory, 0.16% more memory total) since MapSelectWorkCacheEntry ends up being larger, and there's no simple way to avoid that that I can see.
I think I'll stick with the current code. That also feels a bit safer since we've gone through the internal testing with it now.

@jakobbotsch
Copy link
Member Author

Some odd MinOpts TP diffs that I wouldn't expect, I want to check why tomorrow.

Seems like MSVC stopped inlining something in fgMorphArgs causing these differences:

Base: 447610812, Diff: 447723040, +0.0251%

?fgMorphArgs@Compiler@@AEAAPEAUGenTreeCall@@PEAU2@@Z                              : 67415 : +4.22% : 60.07% : +0.0151%
?AddFinalArgsAndDetermineABIInfo@CallArgs@@QEAAXPEAVCompiler@@PEAUGenTreeCall@@@Z : 43536 : +1.79% : 38.79% : +0.0097%
memcpy                                                                            : 1052  : +0.25% : 0.94%  : +0.0002%
memset                                                                            : 225   : +0.01% : 0.20%  : +0.0001%

Apparently MSVC decided it is no longer profitable to inline fgMakeOutgoingStructArgCopy based on these VN changes: https://www.diffchecker.com/GP97PRNx/
Not really sure how that works out, but given that inline decisions are likely completely changed by native PGO, it feels safe to ignore.

@jakobbotsch
Copy link
Member Author

The still running job seems to be some unrelated infra issue:

##[warning]Agent  was purged, cancelling the pipeline.
,##[warning]Received request to deprovision: The request was cancelled by the remote provider.

Not sure why it is still showing as running.

@jakobbotsch jakobbotsch merged commit 0f2719e into dotnet:main Oct 12, 2023
@jakobbotsch jakobbotsch deleted the fix-valuenum-exponential branch October 12, 2023 14:58
@jakobbotsch
Copy link
Member Author

/backport to release/8.0

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6497391189

@ghost ghost locked as resolved and limited conversation to collaborators Nov 11, 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.

JIT: Exponential blowup in VNForMapSelectWork

2 participants