Forward repeated finalize storage reads#29545
Closed
1sgtpepper wants to merge 3 commits into
Closed
Conversation
This was referenced Jun 20, 2026
1sgtpepper
marked this pull request as ready for review
June 22, 2026 03:24
1sgtpepper
marked this pull request as draft
June 26, 2026 10:10
1sgtpepper
marked this pull request as ready for review
June 26, 2026 12:52
1sgtpepper
marked this pull request as draft
June 29, 2026 05:18
1sgtpepper
force-pushed
the
fix/29343-storage-read-forwarding
branch
5 times, most recently
from
June 30, 2026 00:27
0c775ff to
716f870
Compare
1sgtpepper
force-pushed
the
fix/29343-storage-read-forwarding
branch
from
June 30, 2026 00:41
716f870 to
731697c
Compare
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
Addresses 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_mapping_getstorage_read_forwarding/repeated_vector_lenstorage_read_forwarding/assert_barrierstorage_read_forwarding/conditional_branch_readsstorage_read_forwarding/call_barrierstorage_read_forwarding::tests::final_run_clears_static_read_factscompiler/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: