Skip to content

feat: add local common subexpression elimination pass#36

Merged
arnoox merged 2 commits intomainfrom
pr-f2/local-cse
Mar 27, 2026
Merged

feat: add local common subexpression elimination pass#36
arnoox merged 2 commits intomainfrom
pr-f2/local-cse

Conversation

@arnoox
Copy link
Copy Markdown
Owner

@arnoox arnoox commented Mar 27, 2026

Summary

  • Adds local_cse as a new post-lowering optimizer pass
  • Within each basic block, identifies repeated pure computations (BinOp, UnOp, Const) keyed by a hashable ExprKey and replaces later occurrences with the variable from the first
  • Derives Hash on BinOp and UnOp in ir/types.rs (required for ExprKey)

Pipeline position

... → copy_prop → local_cse → gvn → dead_instrs → branch_fold → dead_instrs → ...

Test plan

  • cargo test -p herkos-core --lib — 208 tests pass (11 new local_cse tests)
  • cargo clippy — clean
  • cargo fmt --check

Stack

This is PR F2 of 4 in the optimizer split. Stacked on PR F1 (pr-f1/branch-fold#35).

PR Pass Status
F1 branch_fold #35
F2 (this) local_cse
F3 gvn pending
F4 licm pending

🤖 Generated with Claude Code

Adds `local_cse` as a new post-lowering optimizer pass. Within each
basic block, identifies repeated pure computations (BinOp, UnOp, Const)
keyed by a hashable ExprKey and replaces subsequent occurrences with the
variable from the first occurrence. Requires Hash on BinOp and UnOp,
which is added to ir/types.rs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@arnoox arnoox changed the base branch from pr-f1/branch-fold to main March 27, 2026 09:09
@arnoox arnoox merged commit 7cbca56 into main Mar 27, 2026
1 check passed
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.

1 participant