In D110057 we moved LoopFlatten to a LoopPassManager. This caused a regression for our 64-bit targets (the 32-bit were unaffected), the pass is no longer triggering for a motivating example. Long story short, the IR is just very different than expected; we try to match loop statements and particular uses of induction variables. The easiest is to just move LoopFlatten to a place in the pipeline where the IR is as expected, which is just before IndVarSimplify. This means we move it from LPM2 to LPM1, so that it actually runs just a bit earlier from where it was running before. IndVarSimplify is responsible for significant rewrites that are difficult to "look through" in LoopFlatten.
One thing I had to do, and am unsure about, is the necessary change to add MemorySSAAnalysis as preserved. Without this, I am running in this assertion failure:
fatal error: error in backend: Loop pass manager using MemorySSA contains a pass that does not preserve MemorySSA
It looks correct to me to add MemorySSA as preserved, but am still investigating this, and thought about sharing this in the mean time.