-
Notifications
You must be signed in to change notification settings - Fork 98
MIR Optimization: Constant Folding & Propagation #701
Copy link
Copy link
Open
Labels
A-codegenArea: code generation and MIRArea: code generation and MIRC-enhancementCategory: an issue proposing an enhancement or a PR with oneCategory: an issue proposing an enhancement or a PR with oneC-perfCategory: an issue highlighting optimization opportunities or PRs implementing suchCategory: an issue highlighting optimization opportunities or PRs implementing suchE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
Metadata
Metadata
Assignees
Labels
A-codegenArea: code generation and MIRArea: code generation and MIRC-enhancementCategory: an issue proposing an enhancement or a PR with oneCategory: an issue proposing an enhancement or a PR with oneC-perfCategory: an issue highlighting optimization opportunities or PRs implementing suchCategory: an issue highlighting optimization opportunities or PRs implementing suchE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.
Summary
Implement constant folding and propagation on MIR to evaluate constant expressions at compile time.
Parent issue: #687
Context
Constant folding evaluates operations with constant operands at compile time:
add(5, 3)→8mul(x, 0)→0(even if x is not constant)and(x, 0xFF)where x isuint8→x(no-op)This reduces bytecode size and gas costs, and enables further optimizations.
Tasks
Basic constant folding
Algebraic simplifications
add(x, 0)→xmul(x, 1)→xmul(x, 0)→0div(x, 1)→xand(x, 0)→0or(x, 0)→xxor(x, 0)→xshl(x, 0)→xsub(x, x)→0xor(x, x)→0Comparison folding
eq(5, 5)→truelt(3, 5)→trueiszero(0)→trueIntegration with lowering
Example
Acceptance Criteria
Estimated Complexity
Small-Medium - Straightforward but many cases to handle
Dependencies