Skip to content

JIT: rework optCanonicalizeLoop - #70792

Merged
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:RefactorOptCanonicalizeLoop
Jun 16, 2022
Merged

AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:RefactorOptCanonicalizeLoop

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Rework loop canonicalization in anticipation of extending it to handle
non-loop edges like those seen in #70569.

The code to fix up flow out of h was not needed and has been removed;
we now assert upstream that no such fix up will be needed.

Rework loop canonicalization in anticipation of extending it to handle
non-loop edges like those seen in dotnet#70569.

The code to fix up flow out of `h` was not needed and has been removed;
we now assert upstream that no such fix up will be needed.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 15, 2022
@ghost ghost assigned AndyAyersMS Jun 15, 2022

ghost commented Jun 15, 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

Rework loop canonicalization in anticipation of extending it to handle
non-loop edges like those seen in #70569.

The code to fix up flow out of h was not needed and has been removed;
we now assert upstream that no such fix up will be needed.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS

ghost commented Jun 15, 2022

Copy link
Copy Markdown
Member Author

@BruceForstall PTAL
cc @dotnet/jit-contrib

No diffs expected.

modified = true;
}
}
bool modified = optCanonicalizeLoop(loopInd);

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't understand why the check of if (optLoopTable[loopInd].lpTop->bbNatLoopNum != loopInd) was removed although the comment says "For loopInd and all contained loops, ensures each loop top's back edges do not come from nested loops."

ghost Jun 15, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We were checking this redundantly; now we just check it down in optCanonicalizeLoop.

I may move that check back up to the caller with my next round of revisions, but the point is we don't need to check it twice.

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah..see it now.

@AndyAyersMS

ghost commented Jun 15, 2022

Copy link
Copy Markdown
Member Author

msbuild crashed building linker tests. should be an issue with the dotnet host and this PR. Am going to retry.

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are there diffs?

Comment thread src/coreclr/jit/optimizer.cpp Outdated
// Canonicalize the loop nest rooted at parent loop 'loopInd'.
// Returns 'true' if the flow graph is modified.
//-----------------------------------------------------------------------------
// optCanonicalizeLoop: Canonicalize a loop nest

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// optCanonicalizeLoop: Canonicalize a loop nest
// optCanonicalizeLoopNest: Canonicalize a loop nest

Comment on lines -2896 to +2900
if (optCanonicalizeLoopNest(child))
{
modified = true;
}
modified |= optCanonicalizeLoopNest(child);

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fwiw, I prefer the previous expression.

ghost Jun 15, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Are there diffs?

No

ghost Jun 15, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Odd that reply ended up there.

In the follow-on changes there will be more reasons to canonicalize loops and pre-screening for them all starts to get clunky.

Comment thread src/coreclr/jit/optimizer.cpp Outdated
BlockToBlockMap* const blockMap = new (getAllocator(CMK_LoopOpt)) BlockToBlockMap(getAllocator(CMK_LoopOpt));
blockMap->Set(t, newT);
optRedirectBlock(b, blockMap);
JITDUMP("Redirecting top->bottom backedge " FMT_BB " -> " FMT_BB " to " FMT_BB " -> " FMT_BB "\n", b->bbNum,

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
JITDUMP("Redirecting top->bottom backedge " FMT_BB " -> " FMT_BB " to " FMT_BB " -> " FMT_BB "\n", b->bbNum,
JITDUMP("Redirecting bottom->top backedge " FMT_BB " -> " FMT_BB " to " FMT_BB " -> " FMT_BB "\n", b->bbNum,

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should just add this output to optRedirectBlock at the point where bbJumpDest or >bbJumpSwt->bbsDstTab[i] is set.

ghost Jun 15, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could, but we won't have a friendly name for the edge unless the caller passes one.

Comment thread src/coreclr/jit/optimizer.cpp Outdated
JITDUMP("in optCanonicalizeLoop: 'top' predecessor " FMT_BB " is in the range of " FMT_LP " (" FMT_BB
".." FMT_BB "); not redirecting its bottom edge\n",
topPredBlock->bbNum, loopInd, t->bbNum, b->bbNum);
// Note we've already redirected t->b above.

ghost Jun 15, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Note we've already redirected t->b above.
// Note we've already redirected b->t above.

@ghost ghost added needs-author-action An issue or pull request that requires more info or actions from the author. and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Jun 15, 2022
@AndyAyersMS
AndyAyersMS merged commit 446e5ad into dotnet:main Jun 16, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 16, 2022
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.

3 participants