Skip to content

Forward repeated finalize storage reads#29545

Closed
1sgtpepper wants to merge 3 commits into
ProvableHQ:masterfrom
1sgtpepper:fix/29343-storage-read-forwarding
Closed

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

Conversation

@1sgtpepper

@1sgtpepper 1sgtpepper commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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 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 a contiguous run 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_mapping_get
  • storage_read_forwarding/repeated_vector_len
  • storage_read_forwarding/assert_barrier
  • storage_read_forwarding/conditional_branch_reads
  • storage_read_forwarding/call_barrier
  • storage_read_forwarding::tests::final_run_clears_static_read_facts
  • 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:

@1sgtpepper
1sgtpepper marked this pull request as ready for review June 22, 2026 03:24
@1sgtpepper
1sgtpepper marked this pull request as draft June 26, 2026 10:10
@1sgtpepper
1sgtpepper marked this pull request as ready for review June 26, 2026 12:52
@1sgtpepper
1sgtpepper marked this pull request as draft June 29, 2026 05:18
@1sgtpepper
1sgtpepper force-pushed the fix/29343-storage-read-forwarding branch 5 times, most recently from 0c775ff to 716f870 Compare June 30, 2026 00:27
@1sgtpepper
1sgtpepper force-pushed the fix/29343-storage-read-forwarding branch from 716f870 to 731697c Compare June 30, 2026 00:41
@1sgtpepper 1sgtpepper closed this Jul 2, 2026
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.

1 participant