-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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: Replace fgMoveHotJumps
with 3-opt utility
#112016
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
cc @dotnet/jit-contrib, @AndyAyersMS PTAL. Diffs are particularly large on x86/x64, where we have variable-length jumps. A common theme I'm seeing in the diffs is where we have some straight-line code that can be entered via more than one predecessor, but the layout improvement for preferring one predecessor over the other is insignificant, so 3-opt now moves a large chunk of code up/down the method, potentially changing the sizes of the jumps inside the range. Such examples usually have large size diffs, but little/no PerfScore diff. TP diffs are a wash; in spending less time on the initial layout, 3-opt has to do more work in some cases. I think I can get the cost of a 3-opt run down a bit in the next few PRs, so hopefully I'll make up for this... Thanks! |
The diffs are indeed pretty large on xarch. It is hard to know if this is an improvement. I wonder if it's worth trying to factor in jump distance as an extra cost factor for xarch (or maybe in general), to encourage compactness. For instance we could increase the cost of a jump by N% if there are N blocks between the source and target, or try and estimate each blocks size and sum that up and add a penalty factor when the jump span is over a threshold (like 128 bytes). All that might be costly, since the cost delta of a swap now requires examining all blocks that have edges into or out of the swapped portions, and not just the blocks at the boundaries. |
I've found even nominal tweaks to our cost model to be quite expensive, so this kind of bookkeeping might be too costly. Since we don't seem to be gaining anything by removing |
fgMoveHotJumps
fgMoveHotJumps
with 3-opt utility
@AndyAyersMS I rewrote
11% size increase sounds plausible from longer branches alone, and I suspect the number of duplicate methods in this collection is partly to blame. TP impact is <0.1% across most collections. |
Part of #107749. Based on the plans outlined in #111989 (comment), we want to remove phases that prematurely tweak the initial layout fed into 3-opt;
fgMoveHotJumps
is one such phase. However, initial attempts to remove it incurred large size increases on x86/x64, suggesting there was some utility in moving blocks closer to their hottest successors to keep the layout compact. To avoid derailing my consolidation plan, I've decided to refactorfgMoveHotJumps
into a utility for 3-opt to use. For now, we will continue to use this pass to try to keep the layout compact. In the future, this functionality may be useful for churning the initial layout into 3-opt to discover new local-optimal layouts.