Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds compiler optimization infrastructure to the pcc C99 compiler, introducing the -O flag to enable optimizations. The changes include two core optimization passes (InstCombine for algebraic simplifications and constant folding, DCE for dead code elimination), comprehensive test coverage, significant refactoring of linearize.rs to improve maintainability, and cleanup of dead code warnings.
- InstCombine pass performs constant folding (2+3→5) and algebraic simplifications (x+0→x, x*1→x, etc.)
- DCE pass removes unused instructions using mark-sweep algorithm
- Optimization passes run iteratively until fixed point (max 10 iterations)
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cc/opt.rs | New optimization pass runner infrastructure with fixed-point iteration |
| cc/instcombine.rs | New instruction combining pass with 1400+ lines of simplification rules |
| cc/dce.rs | New dead code elimination pass with mark-sweep algorithm |
| cc/tests/features/optimization.rs | Comprehensive correctness tests for optimization passes |
| cc/tests/common/mod.rs | Added helpers for running tests with optimization flags |
| cc/linearize.rs | Large refactoring extracting helper methods for better code organization |
| cc/ir.rs | Added helper methods for pseudo management (next_pseudo_id, create_const_pseudo) |
| cc/main.rs | Added -O CLI flag and optimization integration point |
| cc/target.rs | Removed unnecessary dead_code allow attributes |
| cc/arch/x86_64/lir.rs | Cleanup: removed unused helper methods, added targeted allow(dead_code) |
| cc/arch/aarch64/lir.rs | Cleanup: removed unused helper methods, added targeted allow(dead_code) |
| cc/TODO.md | Added detailed documentation for future optimization passes |
| cc/README.md | Updated feature list noting constant expression evaluation not yet implemented |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.