-
Notifications
You must be signed in to change notification settings - Fork 95
MIR Optimization: Common Subexpression Elimination (CSE) #703
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 CSE to eliminate redundant computations by reusing previously computed values.
Parent issue: #687
Context
CSE identifies when the same computation is performed multiple times and reuses the first result:
In SSA form, this is straightforward: hash instructions by (opcode, operands) and reuse matching values.
Tasks
Local CSE (within basic blocks)
(opcode, operands, type)Instruction canonicalization
add(y, x)canonicalizes toadd(x, y)for consistent hashingSide effect handling
SLOADwith same slot can be CSE'd if no interveningSSTOREMLOADsimilarly, if no interveningMSTOREGlobal CSE (optional, advanced)
Example
Patterns to follow
From Venom:
From Sonatina:
Acceptance Criteria
Estimated Complexity
Medium - Local CSE is simple, global CSE is harder
Dependencies