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

Adds a new MIR optimization and centralizes block-parameter constant propagation logic.

  • Introduces CopyPropagation pass that replaces simple local loads/uses with Constant when provably constant; integrates visitor to rewrite operands and track constants across assignments
  • Extracts propagate_block_params into cp/mod.rs to compute per-parameter constant consensus from predecessors; reused by InstSimplify
  • Enhances Operand with as_place() and as_constant() helpers for cleaner matching
  • Updates InstSimplify to use shared propagation and evaluated.lookup(...); minor internal refactors
  • Exposes pass via transform/mod.rs and adds snapshot tests covering constant chains, block params (agree/disagree), effectful preds, projections, and loop back-edges

Written by Cursor Bugbot for commit 049e36c. 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

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 21, 2025

CodSpeed Performance Report

Merging #8207 will not alter performance

Comparing bm/be-255-hashql-add-copy-propagation-pass (049e36c) with bm/be-231-hashql-peephole-optimization (08246f0)

Summary

✅ 17 untouched

@codecov
Copy link

codecov bot commented Dec 21, 2025

Codecov Report

❌ Patch coverage is 92.32614% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.14%. Comparing base (08246f0) to head (049e36c).

Files with missing lines Patch % Lines
...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 ⚠️
...hashql/mir/src/pass/transform/inst_simplify/mod.rs 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                            Coverage Diff                             @@
##           bm/be-231-hashql-peephole-optimization    #8207      +/-   ##
==========================================================================
+ Coverage                                   59.03%   59.14%   +0.11%     
==========================================================================
  Files                                        1195     1197       +2     
  Lines                                      113298   113673     +375     
  Branches                                     5046     5056      +10     
==========================================================================
+ Hits                                        66880    67234     +354     
- Misses                                      45644    45663      +19     
- Partials                                      774      776       +2     
Flag Coverage Δ
rust.hashql-compiletest 46.65% <ø> (ø)
rust.hashql-mir 88.29% <92.32%> (+0.20%) ⬆️

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.

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.

2 participants