[6.4.1] LoopInvariantCodeMotion: don't hoist and sink store [assign] - #92506
Merged
Merged
Conversation
This was accidentally enabled by 4114b28, which moved the collection of `loadsAndStores` from `collectMovableInstructions` (where stores with an `assign` ownership were filtered out) to the new `collectSpeculativelyMovableInstructions`, which doesn't filter at all. `hoistAndSinkLoadAndStore` doesn't support `store [assign]`: it erases the store without destroying the overwritten value, which leaks the value coming from the SSAUpdater's phi argument Reject such access paths in `isOnlyLoadedAndStored` again and remove the now dead ownership check in `collectMovableInstructions`. Fixes an ownership verifier error rdar://183953843 (cherry picked from commit 3f5c32d)
store [assign]store [assign]
Contributor
Author
|
@swift-ci test |
tbkka
approved these changes
Sep 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Explanation:
We're hitting an error (
SIL memory lifetime failure in <symbol>: memory is not initialized, but should be) when building some of our internal projects in release mode against a 6.4.x snapshot toolchain. I couldn't reproduce with recent main snapshots. I initially thought it was because that mem2reg pass was removed on main, but I was able to narrow this down to being resolved by LoopInvariantCodeMotion: don't hoist and sinkstore [assign]#91219.We do have a short-term workaround to remove the inlining on the code that triggers this, but it causes a pretty severe performance regression that we can't afford to incur in the longer term.
Scope:
Limited to
LoopInvariantCodeMotion. The change breaks out of a previously attempted optimization when there's astore [assign]in the loop.Issues:
rdar://183953843
6.4.0 miscompile: dead-store elimination incorrectly deletes the defer writeback #92486
Original PRs:
main: LoopInvariantCodeMotion: don't hoist and sink
store [assign]#912196.4.x: [🍒 6.4] LoopInvariantCodeMotion: don't hoist and sink
store [assign]#91509Risk:
Low. It's a trivial change which makes load-store optimization in LICM more conservative. This drops an optimization opportunity that lead to a crash and failure to compile in release mode.
Testing:
Adds
dont_hoist_store_assigntest case totest/SILOptimizer/licm.sil. Locally, I've also built a toolchain from a recent 6.4.x snapshot plus this commit and confirmed that a package which reproduces the failure builds successfully.Reviewers:
@aidan-hall