-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Compiler::optInvertWhileLoop()
contains the check:
if (fgIsForwardBranch(block) == false)
{
return;
}
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