Forward repeated finalize storage reads#29545
Open
Kuhai9801 wants to merge 35 commits into
Open
Conversation
This was referenced Jun 20, 2026
This reverts commit d2f1909.
This reverts commit 43cea5c.
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.
Motivation
Fixes part of #29343.
Lowered finalize code can contain repeated identical static storage reads, such as repeated
Mapping::get_or_use,Mapping::contains, or vector length reads. After CSE, these reads are still separate lowered storage intrinsics, so DCE cannot remove the duplicated read work.This PR adds a separate
StorageReadForwardingpass after CSE and before DCE. It reuses repeated local static storage reads when the mapping/key/default operands are stable atoms.The pass is conservative:
_mapping_get,_mapping_get_or_use, and_mapping_containsTest Plan
Added regression coverage:
storage_read_forwarding/repeated_mapping_readsstorage_read_forwarding/repeated_vector_lenstorage_read_forwarding/assert_barrierstorage_read_forwarding/conditional_branch_readscompiler/storage/external_same_named_mapping_readsThe conditional-branch coverage includes the same-condition SSA join case and negative cases for different conditions and opposite-branch operands.
Verification performed:
git diff --checkorigin/masterRelated PRs
Part of the #29343 optimizer cleanup series.
Related PRs: