Async statemachine for methods with loop generate irreducible CFGs #39814
Labels
Area-Compilers
Code Gen Quality
Room for improvement in the quality of the compiler's generated code
Milestone
An irreducible CFG isn't possible to generate in C# other than via the statemachine generator (or IL Emit) as while C# allows gotos; it won't let you jump into a loop from outside.
However, consider the method
This will generate a loop in the MoveNext() method with 3 entry points and an irreducible control flow:
It would be easier for analysis and optimizations if it was a reducible control flow with only one loop entry point.
For example in the above this could be achieved if the IL_006c block (
awaiter.GetResult();
<i>5__1++;
) was repeated in thenum/state == 0
and before the last goto removing that block entirely, so becoming (better approaches probably also available):The irreducible flow control in IL (as its not exactly the same as the decompiled C# sharplab.io:
The text was updated successfully, but these errors were encountered: