-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve loop inversion #52347
Improve loop inversion #52347
Conversation
When doing loop inversion, we duplicate the condition block to the top of the loop to create a fall-through zero trip test. Improve this by redirecting all incoming branches to the condition block that appear to be coming from outside the potential loop body to branch to the new duplicated condition block. This improves the ability of the loop recognizer to find loops, whereas before we would reject the loops as "multi-entry". There are good diffs where more loops are detected, leading to better optimization and more loop alignment. There are also asm diffs regressions.
Perf results on BenchmarksGame and BenchI shows a big improvement in BenchE (which was the goal), and no obvious above-the-noise diff in the others.
|
There are some asserts that need to be addressed: |
/azp run runtime-coreclr jitstress |
Azure Pipelines successfully started running 1 pipeline(s). |
x64 diffsasm.aspnet.run.windows.x64.checked.4
Detail diffs
asm.benchmarks.run.windows.x64.checked.3
Detail diffs
asm.libraries.crossgen.windows.x64.checked.3
Detail diffs
asm.libraries.crossgen2.windows.x64.checked.2
Detail diffs
asm.libraries.pmi.windows.x64.checked.2
Detail diffs
asm.tests.pmi.windows.x64.checked
Detail diffs
asm.tests_libraries.pmi.windows.x64.checked
Detail diffs
x86 diffsasm.benchmarks.run.windows.x86.checked.1
Detail diffs
asm.libraries.crossgen.windows.x86.checked.1
Detail diffs
asm.libraries.crossgen2.windows.x86.checked.1
Detail diffs
asm.libraries.pmi.windows.x86.checked.1
Detail diffs
asm.tests.pmi.windows.x86.checked
Detail diffs
asm.tests_libraries.pmi.windows.x86.checked.1
Detail diffs
|
@AndyAyersMS @dotnet/jit-contrib PTAL |
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.
Looks good.
// Redirect the predecessor to the new block. | ||
JITDUMP("Redirecting non-loop " FMT_BB " -> " FMT_BB " to " FMT_BB " -> " FMT_BB "\n", predBlock->bbNum, | ||
bTest->bbNum, predBlock->bbNum, bNewCond->bbNum); | ||
optRedirectBlock(predBlock, &blockMap, /*updatePreds*/ true); |
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.
Since we expect optRedirectBlock
to actually do something, I wonder if it should return a bool indicating that it made changes..?
Or, perhaps verify after all this redirecting that the block and the cloned block now have the expected numbers of preds?
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.
Hmmm... I think the only way it could fail to redirect is if the predecessor is BBJ_NONE, which shouldn't occur. I suppose your suggestion is just to assert this. (Other types like BBJ_THROW, BBJ_RETURN, should never be predecessors.)
It turns out if it ends up not redirecting the pred, it's not fatal anyway, it's just sub-optimal.
test failure is #51543 |
When doing loop inversion, we duplicate the condition block to the
top of the loop to create a fall-through zero trip test. Improve
this by redirecting all incoming branches to the condition block
that appear to be coming from outside the potential loop body
to branch to the new duplicated condition block. This improves the
ability of the loop recognizer to find loops, whereas before we
would reject the loops as "multi-entry".
There are good diffs where more loops are detected, leading to
better optimization and more loop alignment.