Skip to content

JIT: update bbNums before inverting loops - #80827

Merged
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:RenumberBlocksForLoopInversion
Jan 19, 2023
Merged

JIT: update bbNums before inverting loops#80827
AndyAyersMS merged 1 commit into
dotnet:mainfrom
AndyAyersMS:RenumberBlocksForLoopInversion

Conversation

@AndyAyersMS

@AndyAyersMS AndyAyersMS commented Jan 19, 2023

Copy link
Copy Markdown
Member

We use the bbNums to decide how to manipulate "in loop" edges when inverting loops, and this was sometimes misleading as the bbNums did not reflect block order.

Per the code this is not a correctness issue, but needless redirections can confuse loop recognition.

Fixes #80809.

Diffs

We use the bbNum to decide how to manipulate "in loop" edges when inverting
loops, and this was sometimes misleading as the bbNums did not reflect block
order.

Per the code this is not a correctness issue, but needless redirections can
confuse loop recognition.

Fixes dotnet#80809.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 19, 2023
@ghost ghost assigned AndyAyersMS Jan 19, 2023
@ghost

ghost commented Jan 19, 2023

Copy link
Copy Markdown

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

Issue Details

We use the bbNum to decide how to manipulate "in loop" edges when inverting loops, and this was sometimes misleading as the bbNums did not reflect block order.

Per the code this is not a correctness issue, but needless redirections can confuse loop recognition.

Fixes #80809.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS

Copy link
Copy Markdown
Member Author

@BruceForstall PTAL
cc @dotnet/jit-contrib

Expect some minor diffs.

@BruceForstall BruceForstall 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.

You decided to explicitly renumber blocks even under SMALL_CODE -- is that to provide a guarantee that the blocks are always properly renumbered after this phase no matter what? (as long as loop inversion is not disabled by config)

@AndyAyersMS

Copy link
Copy Markdown
Member Author

You decided to explicitly renumber blocks even under SMALL_CODE -- is that to provide a guarantee that the blocks are always properly renumbered after this phase no matter what? (as long as loop inversion is not disabled by config)

Wasn't quite sure what the exit contract should be. Right now it's a bit of a mess:

  • if we don't optimize then the phase doesn't run (so no renumbering)
  • if we optimize but have small code we renumber and on exit those numbers are still valid
  • if we invert we add new blocks so the renumbering is no longer valid

Happy to reconsider this, I manly wanted to fix behavior so my follow-on changes for pred lists are no diff, and it appears downstream somewhere we are evidently careful/consistent about renumbering.

@BruceForstall

Copy link
Copy Markdown
Contributor

Seems like it's better to renumber (and/or assert renumbering is not needed) before a phase starts that requires it, rather than (sometimes) renumbering to leave the numbers "canonical" after a phase.

@AndyAyersMS

AndyAyersMS commented Jan 19, 2023

Copy link
Copy Markdown
Member Author

Seems like it's better to renumber (and/or assert renumbering is not needed) before a phase starts that requires it, rather than (sometimes) renumbering to leave the numbers "canonical" after a phase.

So you think I should leave this as is? Or make changes?

[edit] Since you approved I'll assume "leaving as is " is acceptable.

@AndyAyersMS
AndyAyersMS merged commit ad9efe8 into dotnet:main Jan 19, 2023
@AndyAyersMS AndyAyersMS mentioned this pull request Jan 20, 2023
44 tasks
mdh1418 pushed a commit to mdh1418/runtime that referenced this pull request Jan 24, 2023
We use the bbNum to decide how to manipulate "in loop" edges when inverting
loops, and this was sometimes misleading as the bbNums did not reflect block
order.

Per the code this is not a correctness issue, but needless redirections can
confuse loop recognition.

Fixes dotnet#80809.
@ghost ghost locked as resolved and limited conversation to collaborators Feb 18, 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: optInvertLoops depends on bbNum ordering but doesn't guarantee it

2 participants