When inserting uses from outside the MemorySSA creation, we don't
normally need to rename uses, based on the assumption that there will be
no inserted Phis (if Def existed that required a Phi, that Phi already
exists). However, when dealing with unreachable blocks, MemorySSA will
optimize away Phis whose incoming blocks are unreachable, and these Phis end
up being re-added when inserting a Use.
There are two potential solutions here:
- Analyze the inserted Phis and clean them up if they are unneeded
(current method for cleaning up trivial phis does not cover this)
- Leave the Phi in place and rename uses, the same way as whe inserting
defs.
This patch use approach 2.
Resolves first test in PR42940.
nit: can we please add a bit to the comment above instead of immediately contradicting it? e.g.
"In cases without unreachable blocks, because uses do not create new may-defs, there are only two cases: [...]"
"In cases with unreachable blocks, where the unnecessary Phis were optimized out, adding the Use [...]"