If the loop limit is not invariant don't directly bail out, but try to make it invariant with makeLoopInvariant.
I precommitted the test case for this in rG20c7ab87a78c.
Well spotted. This patch was part of my grand master plan to support different phi types, and this patch was to get the first little obstacle out of the way. But because of changes in D88880, the input IR and test case might not be so relevant anymore, so I will look at that first now because I still think this is little change is useful.