Skip to content

Commit

Permalink
JIT: Port VN and loop hoisting to new loop representation (#95589)
Browse files Browse the repository at this point in the history
Switch VN to use the new loop representation for the limited amount of
stuff it does. This is mainly computing loop side effects and using it
for some more precision, in addition to storing some memory dependencies
around loops.
It requires us to have a block -> loop mapping, so add a
BlockToNaturalLoopMap class to do this. We really do not need this
functionality for much, so we may consider seeing if we can remove it in
the future (and remove BasicBlock::bbNatLoopNum).

In loop hoisting move a few members out of LoopDsc and into
LoopHoistContext; in particular the counts of hoisted variables, which
we use for profitability checks and which gets updated while hoisting is
going on for a single loop. We do not need to refer to the information
from other loops.

Record separate postorder numbers for the old and new DFS since we need
to use both simultaneously after loop unrolling. We will be able to get
rid of this again soon.

A small number of diffs are expected because the loop side effects
computation is now more precise, since the old loop code includes some
blocks in loops that are not actually part of the loop. For example,
blocks that always throw can be in the lexical range and would
previously cause the side effect computation to believe there was a
memory havoc. Also, the side effect computation does some limited value
tracking of assignment, which is more precise now since it is running in
RPO instead of based on loop order before.
  • Loading branch information
jakobbotsch authored Dec 7, 2023
1 parent 8851d12 commit 03c2d25
Show file tree
Hide file tree
Showing 15 changed files with 794 additions and 548 deletions.
5 changes: 3 additions & 2 deletions src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,9 @@ BasicBlock* BasicBlock::New(Compiler* compiler)

block->bbNatLoopNum = BasicBlock::NOT_IN_LOOP;

block->bbPreorderNum = 0;
block->bbPostorderNum = 0;
block->bbPreorderNum = 0;
block->bbPostorderNum = 0;
block->bbNewPostorderNum = 0;

return block;
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -1220,8 +1220,9 @@ struct BasicBlock : private LIR::Range

void* bbSparseCountInfo; // Used early on by fgIncorporateEdgeCounts

unsigned bbPreorderNum; // the block's preorder number in the graph (1...fgMaxBBNum]
unsigned bbPostorderNum; // the block's postorder number in the graph (1...fgMaxBBNum]
unsigned bbPreorderNum; // the block's preorder number in the graph (1...fgMaxBBNum]
unsigned bbPostorderNum; // the block's postorder number in the graph (1...fgMaxBBNum]
unsigned bbNewPostorderNum; // the block's postorder number in the graph [0...postOrderCount)

IL_OFFSET bbCodeOffs; // IL offset of the beginning of the block
IL_OFFSET bbCodeOffsEnd; // IL offset past the end of the block. Thus, the [bbCodeOffs..bbCodeOffsEnd)
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5765,6 +5765,9 @@ void Compiler::RecomputeLoopInfo()
optSetBlockWeights();
// Rebuild the loop tree annotations themselves
optFindLoops();

m_dfsTree = fgComputeDfs();
optFindNewLoops();
}

/*****************************************************************************/
Expand Down
Loading

0 comments on commit 03c2d25

Please sign in to comment.