As mentioned in D96979, I'm extending the IsGuaranteedLoopInvariant check also to the MemorySSA.cpp file.
@fhahn For now I didn't unify the function into MemorySSA.h because, as you mentioned, it's not directly MSSA related. I'm open to suggestions to find a better place so we can improve the unification process.
I was also wondering if it would make sense to have a utility function called isEntryBlockInstruction (part of llvm::Instruction) to avoid the ugly check used in this (and the mentioned) patch.
I didn't provide a test yet, because it's not clear to me how to create one that is showing the improvement in the MemorySSA case.