CodeGenPrepare may invalidate the domtree. At the moment, there's no way to selectively preserve passes, so we need to be conservative and never preserve it.
Thank you! :) Like said, D16984 seems to absorb this change, so I'll commit this if we decide to abandon that.
As CGP is the last pass run before SDAG, how exactly did you find this bug out of interest?
I wrote a script that more or less appends -basicaa -verify-memoryssa to all opt runlines in our test suite. This caused a CGP test that was originally just running -loop-unroll -codegenprepare to segfault, because the domtree was pointing to deleted basic blocks when it was handed to MemorySSA.