For-Split Transformation

Split a sinlge loop into two separate one

Today we’re kicking off a new series of posts called “emmtrix Tech Posts”. In this recurring series we want to give a few insights into the development at emmtrix.

In our constant quest to improve the capabilities of our code transformations, we have refactored our for-split transformation. Its goal is to split a single loop like

into two separate ones like

While this can be done in a single transformation, it’s always better to implement it using a combination of already tested functionality from our framework. This can be achieved by starting with a simple split of the for-loop to cover two ranges as defined be the conditions:

If this is followed by constant folding, the two loops become

and

All that is left to do is to apply an additional step to simplify the if- and for-blocks: Remove If-blocks with a constant condition and only keep the corresponding true or false path.

Cookie Consent with Real Cookie Banner