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 optimization and removes duplicated logic.

  • New pass: CopyPropagation replaces uses of locals with known Constants and records constants through simple loads; ignores projections and effectful predecessors; no loop fixpoint
  • Shared util: Extracts propagate_block_params(...) for constant agreement across predecessors; used by both CopyPropagation and InstSimplify
  • API tweaks: Adds Operand::as_place() and Operand::as_constant() helpers; switches to LocalVec::lookup in simplification logic
  • Wiring & tests: Exposes pass from transform/mod.rs and adds comprehensive snapshot tests under cp/

Written by Cursor Bugbot for commit 09dc1b6. 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

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@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 (09dc1b6) with bm/be-231-hashql-peephole-optimization (08246f0)1

Summary

✅ 17 untouched

Footnotes

  1. No successful run was found on bm/be-231-hashql-peephole-optimization (7b8639a) during the generation of this report, so bab8f23 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@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.27%. Comparing base (7b8639a) to head (09dc1b6).

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.01%   59.27%   +0.25%     
==========================================================================
  Files                                        1187     1191       +4     
  Lines                                      112499   113436     +937     
  Branches                                     4939     4982      +43     
==========================================================================
+ Hits                                        66392    67234     +842     
- Misses                                      45349    45426      +77     
- Partials                                      758      776      +18     
Flag Coverage Δ
rust.hashql-compiletest 46.65% <ø> (ø)
rust.hashql-mir 88.29% <92.32%> (+0.11%) ⬆️

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
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