Unswitching

A loop containing a loop-invariant IF statement can be transformed into an IF statement containing two loops.

Example:

In the example below, the IF expression is loop-invariant, and can be hoisted out of the loop.

for (i = 0; i < N; i++)
  if (x)
    a[i] = 0;
  else
    b[i] = 0;
  

After unswitching, the IF expression is only executed once, thus improving run-time performance.

if (x)
  for (i = 0; i < N; i++)
    a[i] = 0;
else
  for (i = 0; i < N; i++)
    b[i] = 0;