Skip to content

Forward repeated finalize storage reads#29545

Open
Kuhai9801 wants to merge 35 commits into
ProvableHQ:masterfrom
Kuhai9801:fix/29343-storage-read-forwarding
Open

Forward repeated finalize storage reads#29545
Kuhai9801 wants to merge 35 commits into
ProvableHQ:masterfrom
Kuhai9801:fix/29343-storage-read-forwarding

Conversation

@Kuhai9801

@Kuhai9801 Kuhai9801 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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 StorageReadForwarding pass 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:

  • forwards _mapping_get, _mapping_get_or_use, and _mapping_contains
  • invalidates tracked reads across mapping writes/removes, final runs, calls, dynamic ops, assert barriers, and unguarded branch exits
  • exposes branch-local aliases only to matching arms of same-condition SSA join ternaries immediately after the branch
  • keeps dynamic storage reads out of scope because they include target program/network operands and need a separate invalidation model

Test Plan

Added regression coverage:

  • storage_read_forwarding/repeated_mapping_reads
  • storage_read_forwarding/repeated_vector_len
  • storage_read_forwarding/assert_barrier
  • storage_read_forwarding/conditional_branch_reads
  • compiler/storage/external_same_named_mapping_reads

The conditional-branch coverage includes the same-condition SSA join case and negative cases for different conditions and opposite-branch operands.

Verification performed:

  • git diff --check
  • conflict-marker scan over changed files
  • merge simulation against origin/master
  • CircleCI PR checks

Related PRs

Part of the #29343 optimizer cleanup series.

Related PRs:

@Kuhai9801 Kuhai9801 marked this pull request as ready for review June 22, 2026 03:24
@Kuhai9801 Kuhai9801 marked this pull request as draft June 26, 2026 10:10
@Kuhai9801 Kuhai9801 marked this pull request as ready for review June 26, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collapse redundant Optional wrapping around storage vector access (option_lowering + ssa_const_propagation)

1 participant