Fix MemorySSA preservation in julia-licm #50315
Merged
+245
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The MemorySSA verification failures were caused by an unfortunate case where we sunk one gc_preserve_end to an exit block, then sunk another one to the same exit block after the first gc_preserve_end. However, we were inserting the MemorySSA use as if we had sunk the second gc_preserve_end to be before the first gc_preserve_end. This fixes the bug by updating the exit point of the loop each time we sink an instruction, so that subsequent sinks do insert at the beginning of the basic block.
There's also a separate bug where the memset for hoisted allocations was marked as a MemoryDef with a LiveOnEntry parent, when it should have been the allocation's MemoryDef. That has also been fixed here.
Tests have been added for both of these cases. Fixes #50305 , and probably addresses the MemorySSA assertion in #50170