Skip to content

Conversation

@indietyp
Copy link
Member

🌟 What is the purpose of this PR?

This PR adds a new Copy Propagation optimization pass to the MIR compiler. The pass identifies when local variables hold constant values and replaces uses of those locals with the constants directly, this is used after InstSimplify, to enable efficient fix point iteration.

🔍 What does this change?

  • Adds a new CopyPropagation transform pass that propagates constant values through the MIR
  • Implements helper methods as_place() and as_constant() on Operand for easier pattern matching
  • Extracts the block parameter propagation logic into a reusable function that can be shared between passes
  • Includes comprehensive test cases covering various scenarios like constant chains, block parameters, and loops

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

🛡 What tests cover this?

  • Comprehensive test suite added in cp/tests.rs covering various scenarios:
    • Basic constant propagation
    • Constant chains through multiple loads
    • Block parameter propagation with unanimous and disagreeing predecessors
    • Handling of effectful predecessors
    • Projections and loop back-edges

@cursor
Copy link

cursor bot commented Dec 21, 2025

PR Summary

Introduces a new MIR transform to replace uses of locals known to hold constants and to propagate constants through block parameters.

  • New CopyPropagation pass (pass/transform/cp/) that records constants and rewrites Operand::Place to Operand::Constant when safe
  • Adds Operand::as_place() and Operand::as_constant() for ergonomic matching
  • Extracts propagate_block_params utility to compute consensus constants from predecessor targets; reused in inst_simplify
  • Updates InstSimplify to call propagate_block_params and use LocalVec::lookup for evaluated locals
  • Exposes the pass via pass/transform/mod.rs
  • Adds targeted tests and snapshots in cp/tests.rs (constants, chains, block params, effectful predecessors, projections, loop back-edges)

Written by Cursor Bugbot for commit 82e5742. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team area/tests New or updated tests labels Dec 21, 2025
Copy link
Member Author

indietyp commented Dec 21, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 21, 2025

Merging this PR will not alter performance

✅ 14 untouched benchmarks
🗄️ 3 archived benchmarks run1


Comparing bm/be-255-hashql-add-copy-propagation-pass (82e5742) with main (372e9a1)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were run, but are now archived. If they were deleted in another branch, consider rebasing to remove them from the report. Instead if they were added back, click here to restore them.

@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

❌ Patch coverage is 86.19600% with 131 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.26%. Comparing base (1892655) to head (9b1c7bc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...hashql/mir/src/pass/transform/inst_simplify/mod.rs 60.90% 80 Missing and 15 partials ⚠️
...ibs/@local/hashql/mir/src/pass/transform/cp/mod.rs 82.60% 17 Missing and 3 partials ⚠️
libs/@local/hashql/mir/src/body/operand.rs 0.00% 10 Missing ⚠️
libs/@local/hashql/core/src/id/vec.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8207      +/-   ##
==========================================
+ Coverage   59.01%   59.26%   +0.24%     
==========================================
  Files        1187     1191       +4     
  Lines      112497   113442     +945     
  Branches     4939     4982      +43     
==========================================
+ Hits        66394    67232     +838     
- Misses      45345    45434      +89     
- Partials      758      776      +18     
Flag Coverage Δ
rust.hashql-compiletest 46.65% <ø> (ø)
rust.hashql-mir 88.29% <86.74%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@graphite-app graphite-app bot requested review from a team December 21, 2025 22:48
@indietyp indietyp force-pushed the bm/be-231-hashql-peephole-optimization branch from 894a7e2 to 08246f0 Compare December 23, 2025 21:16
@indietyp indietyp force-pushed the bm/be-255-hashql-add-copy-propagation-pass branch from 0c57079 to 049e36c Compare December 23, 2025 21:16
@indietyp indietyp force-pushed the bm/be-255-hashql-add-copy-propagation-pass branch from 049e36c to 09dc1b6 Compare December 28, 2025 11:17
@indietyp indietyp force-pushed the bm/be-231-hashql-peephole-optimization branch from 08246f0 to 7b8639a Compare December 28, 2025 11:17
@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
ds-theme Ignored Ignored Preview Jan 15, 2026 2:06pm
hashdotdesign Ignored Ignored Preview Jan 15, 2026 2:06pm

Base automatically changed from bm/be-231-hashql-peephole-optimization to main January 15, 2026 14:05
@indietyp indietyp force-pushed the bm/be-255-hashql-add-copy-propagation-pass branch from 9b1c7bc to 82e5742 Compare January 15, 2026 14:05
@vercel vercel bot temporarily deployed to Preview – petrinaut January 15, 2026 14:05 Inactive
@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 15, 2026

Merge activity

  • Jan 15, 2:06 PM UTC: Graphite rebased this pull request, because this pull request is set to merge when ready.
  • Jan 16, 12:45 PM UTC: A user started a stack merge that includes this pull request via Graphite.

@indietyp indietyp added this pull request to the merge queue Jan 15, 2026
Merged via the queue into main with commit 86f263f Jan 15, 2026
47 checks passed
@indietyp indietyp deleted the bm/be-255-hashql-add-copy-propagation-pass branch January 15, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team

Development

Successfully merging this pull request may close these issues.

3 participants