Open kunalspathak opened 2 years ago
@dotnet/jit-contrib
See also https://github.com/dotnet/runtime/issues/9833#issuecomment-372847082 (a few years old now)
Tagging subscribers to this area: @JulieLeeMSFT See info in area-owners.md if you want to be subscribed.
Author: | kunalspathak |
---|---|
Assignees: | kunalspathak |
Labels: | `area-CodeGen-coreclr` |
Milestone: | - |
Some more ideas:
LSRA comes up with a block order in which it would allocate register for the code inside it. It would sequence all the predecessors of a block before scheduling a block. It also compares the
bbWeight
of a block and gives preference to the block with higher weights. It is not uncommon to have multiple blocks of same weight (either because of lack of enough profile data or other reasons) and in such cases, we rely on the block number of the block as seen below.https://github.com/dotnet/runtime/blob/96ef47b2c6d6591cebba4eb260763576621e8236/src/coreclr/jit/lsra.cpp#L1030-L1060
This is arguably not a good heuristic to arrange LSRA block sequencing. The
bbNum
are purely dependent on the how the blocks are laid out our data structure and might not represent the flow graph. The original thinking could be that the blocks with lowerbbNum
are executed first than the ones with higher numbers, but still, it is not the optimal strategy to have. If the blocks are renumbered, it can drastically change the allocation strategy because of different block sequencing coming out of it. This was seen in https://github.com/dotnet/runtime/pull/66967 where I had to skip renumbering the blocks so the impact of "unreachable block elimination" doesn't regress register allocation.Just to give a sense, I tried following strategies and the impact it has on code size is huge.
block1
overblock2
ifblock1
has more predecessors than those ofblock2
.block1
overblock2
ifblock1
has less predecessors than those ofblock2
.block1
overblock2
ifblock1
has morebbReach
nodes than those ofblock2
.block1
overblock2
ifblock1
has lessbbReach
nodes than those ofblock2
.Some other strategies could be:
bbWeight
but should double check).A clever way is to have a mix of above listed strategies in choosing the block sequencing.
category:design theme:register-allocator skill-level:expert cost:medium impact:large