Skip to content

[codex] Hoist invariant numeric array reads in inner loops#5312

Closed
andrewtdiz wants to merge 3 commits into
codex/perry-numeric-array-guard-precheckfrom
codex/perry-invariant-array-read-hoist
Closed

[codex] Hoist invariant numeric array reads in inner loops#5312
andrewtdiz wants to merge 3 commits into
codex/perry-numeric-array-guard-precheckfrom
codex/perry-invariant-array-read-hoist

Conversation

@andrewtdiz

Copy link
Copy Markdown
Contributor

Summary

  • hoist invariant numeric arr[i] reads out of eligible inner for (...; j < arr.length; j++) loops
  • split the inner-loop CFG so only first entry runs the hoisted guard load; backedges skip the prebody
  • add bulk typed-feedback fast-pass accounting for skipped guard calls, plus positive and negative IR tests

Benchmarks

Baseline is ec79e68ff on codex/perry-i32-array-index-lowering; current commit is 5895ca8e7.

  • direct 10_nested_loops: 221ms -> 102ms median, sum 26991000000 throughout
  • perf stat direct nested: 813.9M -> 422.6M cycles, 3.64B -> 1.84B instructions, 820.6M -> 415.4M branches
  • typed-feedback trace: both numeric array get sites still report 9,000,000 observations/passes, 0 failures, 0 fallbacks
  • benchmarks/quick.sh: nested_loops 202ms -> 124ms; matrix_multiply stayed in range at 387ms -> 390ms
  • benchmarks/compare.sh --quick --runs 3 --warn-only: nested_loops 214ms -> 101ms; JSON at /tmp/perry-compare-invariant-hoist-final.json

Note: local Node.js cannot execute .ts benchmark inputs here, so Node columns/correctness checks were skipped by the harness. benchmarks/baseline.json is stale for this Linux environment, so compare was run with --warn-only and PR deltas use the captured local #5310 baseline.

Validation

  • cargo fmt --check
  • git diff --check
  • cargo test -p perry-codegen --test typed_feedback
  • cargo test -p perry-codegen --test typed_shape_descriptors
  • PERRY_BIN=target/release/perry python3 tests/test_typed_feedback_runtime_evidence.py
  • tests/test_benchmark_output_verifier.sh
  • cargo build --release

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e8c88752-58c3-4622-982c-c6ef351c7c55

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/perry-invariant-array-read-hoist

Comment @coderabbitai help to get the list of available commands and usage tips.

@andrewtdiz andrewtdiz force-pushed the codex/perry-invariant-array-read-hoist branch from 5895ca8 to f8454f6 Compare June 17, 2026 07:47
@proggeramlug proggeramlug force-pushed the codex/perry-i32-array-index-lowering branch from ec79e68 to 4a132f8 Compare June 17, 2026 13:38
@proggeramlug proggeramlug force-pushed the codex/perry-invariant-array-read-hoist branch from f8454f6 to 20f67fe Compare June 17, 2026 13:38
@proggeramlug proggeramlug force-pushed the codex/perry-i32-array-index-lowering branch from 4a132f8 to 33e8555 Compare June 17, 2026 13:47
@proggeramlug proggeramlug force-pushed the codex/perry-invariant-array-read-hoist branch from 20f67fe to 44c070b Compare June 17, 2026 13:47
@proggeramlug proggeramlug force-pushed the codex/perry-i32-array-index-lowering branch from 33e8555 to d966c2c Compare June 17, 2026 13:58
@proggeramlug proggeramlug force-pushed the codex/perry-invariant-array-read-hoist branch from 44c070b to 8a96726 Compare June 17, 2026 13:58
@proggeramlug proggeramlug marked this pull request as ready for review June 18, 2026 05:40
@proggeramlug proggeramlug force-pushed the codex/perry-i32-array-index-lowering branch from d966c2c to fd22011 Compare June 18, 2026 06:36
@proggeramlug proggeramlug force-pushed the codex/perry-invariant-array-read-hoist branch from 8a96726 to e10ff31 Compare June 18, 2026 06:36
@proggeramlug proggeramlug reopened this Jun 18, 2026
Base automatically changed from codex/perry-i32-array-index-lowering to codex/perry-numeric-array-guard-precheck June 18, 2026 17:55
@proggeramlug

Copy link
Copy Markdown
Contributor

Closing as superseded. Since this codex stack was cut, main advanced 52+ commits and independently evolved the same hot codegen/runtime paths. This PR is one link in a 13-deep linear stack that conflicts with diverged, correctness-sensitive codegen and was never reviewed; landing it would mean rebasing the whole stack. It was also flagged as borderline in per-PR review (narrow win and/or unrelated scope creep bundled in).

Specific: bespoke split-CFG (for.prebody/for.cond.backedge) for a narrow single-expression inner-loop shape; high maintenance surface for a benchmark-specific win. A general LICM pass is preferable.

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.

2 participants