Currently, the attached test case fails with an assert in MemorySSAUpdater::fixupDefs:
// We are now this def's defining access, make sure we actually dominate // it assert(MSSA->dominates(NewDef, FirstDef) && "Should have dominated the new access");
See https://github.com/llvm/llvm-project/issues/51257
This happens because we are trying to insert a def in dead code. In this test case GVN attempts to merge baz.invoke block into dead.block (both blocks are dead, i.e. unreachable from entry). This triggers an update to MemorySSA with the following call chain:
MergeBlockIntoPredecessor MemorySSAUpdater::moveToPlace MemorySSAUpdater::moveTo MemorySSAUpdater::insertDef MemorySSAUpdater::fixupDefs
fixupDefs asserts that the new defining access dominates the memory access being updated. This assert fails for dead code because DomTree doesn't provide dominance information for blocks not reachable from entry (it simply returns false).
When constructing a fresh MSSA we mark all memory accesses in dead code as live-on-entry. In this patch, I do the same for incremental updates via insertDef.