-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: Move backward jumps to before their successors after RPO-based layout #102461
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
New codegen for the example linked in this comment:
|
Edit: Looking at the diffs again, I don't think this exception is a good idea. Reverted. |
This reverts commit f9d81a9.
It's probably worth considering only BBJ_ALWAYS and BBJ_COND here, which makes finding the preferred successor simpler. In the phoenix version the similar bit of code keyed off of RPO back edges. If a back edge source was not a BBJ_COND, and the target of the back edge was not following its most likely pred, we'd move the back edge source block up. Another way of saying this is that we'd really like the last block in the loop body to be an exit block. |
I see, I think I can simplify this PR quite a bit then. I'm guessing Phoenix wouldn't do this for (also, sorry to loop you in while you're OOF) |
I've simplified my approach to only consider backward, unconditional jumps, and this seems to solve all the mis-rotated loop examples we looked at in #102343 while keeping churn and TP cost pretty low. This implementation is pretty narrow in the flowgraph shapes it's trying to fix, but since this work was motivated by the misshapen loop regressions, I think we can keep this conservative until we find a need for other passes to tweak the RPO-based order. @EgorBo do you have any time to look at this today? If not, no worries; I think @jakobbotsch will be online tomorrow. Thanks! |
LGTM as far as I can tell, I presume the newer commits you've pushed should still be zero diffs since it's RPO is not enabled, right? |
Yes, that's right. I re-ran SPMI locally and updated the gist. TP impact is now <= 0.03%. |
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.
LGTM as well. I think a simple targeted fix like this is just fine, but of course it would be nice with something a little more general in the future.
I saw you commented on #9304, but I wasn't sure what the final result ended up being; does this PR help there as well?
Thank you for the reviews! No diffs.
It does fix the loop rotation issue there as well, though the final layout isn't any better than what we started with. I'll elaborate more over there. |
Follow-up to dotnet#102461, and part of dotnet#9304. Compacting blocks after establishing an RPO-based layout, but before moving backward jumps to fall into their successors, can enable more opportunities for branch removal; see dotnet#9304 for one such example.
…ayout (dotnet#102461) Part of dotnet#93020. In dotnet#102343, we noticed the RPO-based layout sometimes makes suboptimal decisions in terms of placing a block's hottest predecessor before it -- in particular, this affects loops that aren't entered at the top. To address this, after establishing a baseline RPO layout, fgMoveBackwardJumpsToSuccessors will try to move backward unconditional jumps to right behind their targets to create fallthrough, if the predecessor block is sufficiently hot.
Follow-up to dotnet#102461, and part of dotnet#9304. Compacting blocks after establishing an RPO-based layout, but before moving backward jumps to fall into their successors, can enable more opportunities for branch removal; see dotnet#9304 for one such example.
Part of #93020. In #102343, we noticed the RPO-based layout sometimes makes suboptimal decisions in terms of placing a block's hottest predecessor before it -- in particular, this affects loops that aren't entered at the top (comment). To address this, after establishing a baseline RPO layout,
fgMoveBackwardJumpsToSuccessors
will try to move backward unconditional jumps to right behind their targets to create fallthrough, if the predecessor block is sufficiently hot.Since the new layout isn't enabled in CI yet, here are the diffs with the baseline using the new RPO layout, on Windows x64: gist. This change is a net size regression, though the PerfScore diffs look promising, and I see many instances of the inverted loop shape fixed. TP impact is <=0.03% over doing just the RPO-based layout.
cc @dotnet/jit-contrib