Loop inversion should consider top-tested loops #50204
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
in-pr
There is an active PR which will close this issue when it is merged
Milestone
Compiler::optInvertWhileLoop()
contains the check:This check is potentially expensive (it iterates over the block list because block numbers are not ordered when this is called).
It is also potentially unnecessary.
Without this check, the loop inversion code works just fine. Instead of the expected pattern, though, it turns top-tested, top-entry loops with an unconditional back-edge to top-tested, top-entry loops with a duplicated condition at the bottom and thus a conditional back-edge. So, it reduces the branches in a loop from 2 to 1, at the cost of the duplicated condition.
There are diffs when removing this check, so the code pattern does exist.
Investigate whether removing this check and enabling this transformation is worthwhile.
category:cq
theme:loop-opt
skill-level:intermediate
cost:small
impact:small
The text was updated successfully, but these errors were encountered: