This pass was used for a 32-bit target, now we want to use it on 64-bit targets too. This pass wasn't triggering on 64-bit targets because the input IR to pass looks slightly different than it was expecting. For example, earlier transformations can perform rewrites using the widest available integer type, and address calculation uses wider 64-bit types. Thus, this change:
- Moves pass LoopFlatten to just before LoopIndvarSimplify in the optimisation pipeline. These passes were already running shortly after each other, but LoopIndvarSimplify can perform rewrites using wider types that makes life more difficult for LoopFlatten. This simple reordering avoids these complications, at no disadvantage for the 32-bit target. For our motivating case on this target I've measured an irrelevant -0.0048% regression as a result of this pass reordering.
- Overflow checks are performed on the GEP instructions. This change looks through a ZExt instruction only if it is used to index a GEP and if there are no other uses that could change the value. I think this is the least intrusive change compared to alternatives, for example promoting loop control instruction to the widest used type if different types are used.