Skip to content

feat: introduce new ir optimizations#12

Open
arnoox wants to merge 26 commits intomainfrom
ir-optimizer
Open

feat: introduce new ir optimizations#12
arnoox wants to merge 26 commits intomainfrom
ir-optimizer

Conversation

@arnoox
Copy link
Owner

@arnoox arnoox commented Feb 28, 2026

contributing to #3

Arnaud Riess added 26 commits February 24, 2026 20:40
refactor: enhance BinOp and UnOp enums with Hash derive
refactor: clean up copy propagation and dead block elimination logic
refactor: merge blocks optimization and update imports
…tant arithmetic

- Added a new module for constant propagation in the optimizer.
- Integrated constant propagation into the optimization pipeline.
- Updated the end-to-end test for constant arithmetic to verify constant folding, ensuring that the expression `10 + 20` is evaluated to `30` at compile time.
- Added a new module `licm.rs` that implements the Loop-Invariant Code Motion optimization.
- The `eliminate` function identifies and hoists loop-invariant instructions from loop headers to preheader blocks.
- Updated `mod.rs` to include the LICM module and integrate it into the optimization pipeline.
- Ensured LICM is executed as part of the optimization process, following copy propagation and local common subexpression elimination.
- Added a new module `licm.rs` that implements the Loop-Invariant Code Motion algorithm.
- The `eliminate` function identifies and hoists loop-invariant instructions from loop headers to preheader blocks.
- Updated the optimizer to include the LICM pass in the optimization sequence.
Implements two optimization passes:

1. Algebraic Simplifications (algebraic.rs)
   - Eliminates identity patterns (x+0, x*1, x^0, etc.)
   - Replaces annihilators (x*0, x&0, etc.)
   - Simplifies self-referential operations (x==x, x^x, etc.)
   - Runs after constant propagation to fold constant operands

2. Branch Condition Folding (branch_fold.rs)
   - Detects single-use comparisons that feed directly into BranchIf
   - Enables codegen to inline comparisons into branch conditions
   - Eliminates the materialize-bool-then-test-bool pattern
   - Generates cleaner, more idiomatic Rust

Both passes are integrated into the optimizer pipeline. Semantic correctness
is prioritized over microbenchmark performance—real programs benefit more
from these optimizations than synthetic fibonacci benchmarks.
The current `copy_prop` only works within a single block. In SSA form, every `Assign { dest, src }` is a global fact.
`dest` is defined exactly once and always equals `src` at the point of definition.
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