Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Dec 7, 2025

No description provided.

@jgarzik jgarzik requested a review from Copilot December 7, 2025 21:47
@jgarzik jgarzik self-assigned this Dec 7, 2025
@jgarzik jgarzik added bug Something isn't working enhancement New feature or request cleanup labels Dec 7, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jgarzik jgarzik merged commit 65bcaec into main Dec 7, 2025
4 checks passed
@jgarzik jgarzik deleted the cc branch December 7, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cleanup enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants