Loop versioning modifies the scop, especially the PHI nodes in the entry and exit block. Code generation must take this into account and test for multiple cases where the PHIs could have landed which can also depend on the code surrounding the scop. Not considering all cases has been a source of many bugs.
With this patch we generate code before modifying the scop region into a region disconnected from the original code. Only after the code has been created, it is connected as an alternative of the original scop region.
Going further with this idea, we could generate all SCoPs in a function before connecting them in order to not require to verify whether other detected SCoPs are still valid.