Skip to content

[codex] Lower loop-bound array indices as i32#5310

Merged
proggeramlug merged 1 commit into
codex/perry-numeric-array-guard-precheckfrom
codex/perry-i32-array-index-lowering
Jun 18, 2026
Merged

[codex] Lower loop-bound array indices as i32#5310
proggeramlug merged 1 commit into
codex/perry-numeric-array-guard-precheckfrom
codex/perry-i32-array-index-lowering

Conversation

@andrewtdiz

Copy link
Copy Markdown
Contributor

Summary

  • expose trusted local loop bounds as temporary i32 slots while lowering loop bodies
  • lower known-array computed get indices through existing i32 expression lowering when all operands are trusted
  • keep the numeric array typed-feedback guard and fallback intact, converting the final i32 index back to double only for the guard argument
  • add an IR regression test for xs[i * size + 1] inside an i < size loop

Why

After the numeric array guard precheck stack, matrix multiplication still spent work rebuilding hot indices like i * size + k through double arithmetic before the typed-feedback get guard. Loop-bound analysis had already hoisted size as an i32 bound, but that slot was not visible to computed index lowering.

Benchmark Notes

Stacked on codex/perry-numeric-array-guard-precheck / PR #5309.

Baseline #5309:

  • direct matrix samples: 400ms, 398ms, 398ms, 385ms, 386ms; median 398ms
  • quick matrix: 407ms
  • perf direct matrix: 1.443B cycles, 7.034B instructions, 1.568B branches, 241K branch misses

This branch:

  • direct matrix 10-sample set: 397ms, 396ms, 390ms, 392ms, 392ms, 393ms, 383ms, 389ms, 386ms, 384ms; median 391ms
  • quick matrix: 387ms
  • perf direct matrix: 1.457B cycles, 7.018B instructions, 1.568B branches, 249K branch misses
  • typed-feedback trace preserved 33,619,968 get passes, 65,536 set passes, 0 get/set failures, and 39 push fallbacks

The wall-time signal is positive and the generated IR removes the double multiply/add index chain from the two hot matmul get sites. The single perf sample is mixed: instructions are slightly lower, while cycles and branch misses are slightly higher.

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
  • target/release/perry compile --no-cache benchmarks/suite/16_matrix_multiply.ts -o /tmp/perry-matrix-i32-index-proto --trace llvm --quiet
  • benchmarks/quick.sh
  • benchmarks/compare.sh --quick --runs 3 --warn-only --json-out /tmp/perry-i32-index-proto.json

@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: fa63c38e-89ef-4925-ae7c-ab4e775996b6

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-i32-array-index-lowering

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

@andrewtdiz andrewtdiz force-pushed the codex/perry-i32-array-index-lowering branch from 554dcdd to ec79e68 Compare June 17, 2026 06:48
@proggeramlug proggeramlug force-pushed the codex/perry-numeric-array-guard-precheck branch from 9667292 to 9bacb98 Compare June 17, 2026 13:38
@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-numeric-array-guard-precheck branch from 9bacb98 to 8a6db40 Compare June 17, 2026 13:47
@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-numeric-array-guard-precheck branch from 8a6db40 to 2095f68 Compare June 17, 2026 13:58
@proggeramlug proggeramlug force-pushed the codex/perry-i32-array-index-lowering branch from 33e8555 to d966c2c 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-numeric-array-guard-precheck branch from 2095f68 to 7f98910 Compare June 18, 2026 06:36
@proggeramlug proggeramlug force-pushed the codex/perry-i32-array-index-lowering branch from d966c2c to fd22011 Compare June 18, 2026 06:36
@proggeramlug proggeramlug reopened this Jun 18, 2026
@proggeramlug proggeramlug merged commit 8d1c99b into codex/perry-numeric-array-guard-precheck Jun 18, 2026
3 checks passed
@proggeramlug proggeramlug deleted the codex/perry-i32-array-index-lowering branch June 18, 2026 17:55
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