The current logic to remove all uses of MemoryAccess defined in dead
blocks from MemoryPhis outside the set of dead blocks. MemoryPhis using
a definition from a dead block do not necessarily have to be in a direct
successor of a dead block, for example if the successor does not contain
any memory accesses.
To catch those additional MemoryPhis that need updating we need to check
all uses of all memory defs in the dead blocks and remove them from any
MemoryPhi outside the set of dead blocks.
Note that we sill need the existing code where we check the successors
for memory phis to catch the case where a MemoryPhi has an incoming
value from a dead block but is not defined in any dead block.
This can happen during unswitching, where a region between the memory
def and a memory phi becomes unreachable.
I *think* there's still a case we might miss in the above case: when the
memory phi is not a direct successor of a dead block. Not sure if this
can happen in practice.
Fixes PR47557.
Note that I did not manage to reduce the test cases so far that it only
requires a single pass to crash.