Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Port loop compaction to new loop representation #96995

Merged
merged 5 commits into from
Jan 18, 2024

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Jan 15, 2024

Some diffs expected from (at least) three sources:

  • Less/different compaction in cases where new loop recognition recognizes fewer loops than old recognition
  • Less compaction in cases where compacting the first loop led to old loop recognition recognizing another loop after the first one. This leads to no BBF_OLD_LOOP_HEADER_QUIRK set on the second loop's header found by new loop finding, meaning we do not compact it. It will be compacted as part of a future PR that enables compaction for all loops.
  • Slight differences in compaction behavior for blocks that aren't part of the loop and that couldn't be moved, which would previously abort compaction and recognition of the loop. Now we just leave those blocks in place.

Some diffs expected from (at least) two sources:
- Less/different compaction in cases where new loop recognition
  recognizes fewer loops than old recognition
- Less compaction in cases where compacting the first loop led to
  old loop recognition recognizing another loop after the first one.
  This leads to no `BBF_OLD_LOOP_HEADER_QUIRK` set on the second loop's
  header found by new loop finding, meaning we do not compact it. It
  will be compacted as part of a future PR that enables compaction for
  all loops.
- Slight differences in compaction behavior for blocks that aren't part
  of the loop and that couldn't be moved, which would previously abort
  compaction and recognition of the loop. Now we just leave those blocks
  in place.
@ghost ghost assigned jakobbotsch Jan 15, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 15, 2024
@ghost
Copy link

ghost commented Jan 15, 2024

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

Issue Details

Some diffs expected from (at least) three sources:

  • Less/different compaction in cases where new loop recognition recognizes fewer loops than old recognition
  • Less compaction in cases where compacting the first loop led to old loop recognition recognizing another loop after the first one. This leads to no BBF_OLD_LOOP_HEADER_QUIRK set on the second loop's header found by new loop finding, meaning we do not compact it. It will be compacted as part of a future PR that enables compaction for all loops.
  • Slight differences in compaction behavior for blocks that aren't part of the loop and that couldn't be moved, which would previously abort compaction and recognition of the loop. Now we just leave those blocks in place.
Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

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

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jan 16, 2024

cc @dotnet/jit-contrib PTAL @BruceForstall

Some minor codegen diffs, see above for why. Ideally we remove this entire compaction step once we get a new block layout algorithm in the backend, so mostly I view this code for now as a way to reduce churn. Unfortunately we will probably see a bunch of diffs when we enable the compaction for new loops as well, but I don't see a simple way to avoid that if we want to be able to remove old loop finding.

The TP regressions are large, but I expect them all to be gone once #96927 is merged -- they come from the extra fgUpdateChangedFlowGraph computation. I still think this should be good to review as the merge after #96927 shouldn't impact too much. Minimal TP diffs now after #96927 made it in.

Comment on lines 4402 to 4408
if (optCompactLoops())
{
fgInvalidateDfsTree();
m_dfsTree = fgComputeDfs();
m_loops = FlowGraphNaturalLoops::Find(m_dfsTree);
modified = true;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason this is needed is because optCompactLoops needs to insert blocks to fix up fallthrough. Otherwise the DFS tree would not be invalidated by it. It would be possible to avoid this by waiting with fixing up the fall through until after we have also canonicalized the loops, e.g. by having some fgFixFallthrough like we discussed the other day.

BasicBlock* previous = cur->Prev();
BasicBlock* nextLoopBlock = lastNonLoopBlock->Next();
assert(previous != nullptr);
if (!BasicBlock::sameEHRegion(previous, nextLoopBlock) || !BasicBlock::sameEHRegion(previous, insertionPoint))
Copy link
Member

Choose a reason for hiding this comment

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

fyi: this code is basically pre-existing, but there's an issue for fixing/improving it: #85550

@jakobbotsch jakobbotsch merged commit 13ab6eb into dotnet:main Jan 18, 2024
126 of 129 checks passed
@jakobbotsch jakobbotsch deleted the compact-on-new-loops branch January 18, 2024 12:12
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
Some diffs expected from (at least) three sources:
- Less/different compaction in cases where new loop recognition
  recognizes fewer loops than old recognition
- Less compaction in cases where compacting the first loop led to
  old loop recognition recognizing another loop after the first one.
  This leads to no `BBF_OLD_LOOP_HEADER_QUIRK` set on the second loop's
  header found by new loop finding, meaning we do not compact it. It
  will be compacted as part of a future PR that enables compaction for
  all loops.
- Slight differences in compaction behavior for blocks that aren't part
  of the loop and that couldn't be moved, which would previously abort
  compaction and recognition of the loop. Now we just leave those blocks
  in place.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 18, 2024
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.

2 participants