You want to avoid branches in hot paths. If you branch inside the loop, lots of branches. If you branch outside the loop (into different specialized loops), few branches. Big fucking deal.
https://en.wikipedia.org/wiki/Loop_unswitching
https://en.wikipedia.org/wiki/Loop_unswitching