Add Strength Reduction and Dead Code Elimination to AST Optimizer#4758
Add Strength Reduction and Dead Code Elimination to AST Optimizer#4758jedel1043 merged 3 commits intoboa-dev:mainfrom
Conversation
Test262 conformance changes
Tested main commit: |
430cad8 to
39ce610
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4758 +/- ##
===========================================
+ Coverage 47.24% 57.98% +10.74%
===========================================
Files 476 559 +83
Lines 46892 61208 +14316
===========================================
+ Hits 22154 35493 +13339
- Misses 24738 25715 +977 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c8d63a3 to
7f909f9
Compare
jedel1043
left a comment
There was a problem hiding this comment.
This is very cool, thank you!
By the way, did you have the opportunity to test if this increases performance in the V8 benchmarks?
37a7ca3 to
7f909f9
Compare
|
sir while running the V8 benchmark tests, I encountered a STATUS_STACK_OVERFLOW when executing combined.js. To investigate, I cloned a fresh copy of boa-dev/boa (latest main, no modifications), built it in release mode, and reproduced the same crash. When running with a larger stack (16 MB thread), all benchmarks completed successfully (Score: 214). also i ran some custom microbenchmarks around the specific patterns introduced by the optimisation passes, and that showed measurable performance improvements to the current boa |
|
No worries! You're probably running this on Windows, which has a much smaller stack size by default than Linux. We're kinda working towards fixing that, but than you for testing it anyways! |
jedel1043
left a comment
There was a problem hiding this comment.
Everything looks good! We can merge this after fixing all the CI warnings
|
Hey, are those test262 still failing? That is a huge red flag that something broke. |
Adds two new AST optimizer passes: - **Strength Reduction**: Optimizes computationally heavy expressions without side effects. Specifically: - Eliminates division `x / 2` in favor of multiplication `x * 0.5`. - Transforms exponents `x ** 2` into `x * x`. Both optimizations use `std::mem::replace` instead of clone to avoid redundant memory allocations. - **Dead Code Elimination**: Removes unreachable `if`, `while`, and `for` branches/loops when the condition is a known boolean literal (after constant folding). Correctly handles JavaScript hoisting semantics by bailing out if the removed body contains `var` declarations, `function` declarations, or generator/async variants. Additionally, prevents side-effect vulnerabilities in `for` loops by refusing to eliminate loops that contain an initialization statement. Also bounds all optimizer pass loops with MAX_PASS_ITERATIONS to prevent infinite loops. Ref: boa-dev#4694
a3bccbd to
74a8be4
Compare
This PR adds two new AST optimizer passes:
Strength Reduction: Optimizes computationally heavy expressions
without side effects. Specifically:
x / 2in favor of multiplicationx * 0.5.x ** 2intox * x.Both optimizations use
std::mem::replaceinstead of clone to avoid redundant memory allocations.Dead Code Elimination: Removes unreachable
if,while, andforbranches/loops when the condition is a known boolean literal (after constant folding).
handles JavaScript hoisting semantics by bailing out if the removed
body contains
vardeclarations,functiondeclarations, or generator/async variants.also, prevents side-effect vulnerabilities in
forloops byrefusing to eliminate loops that contain an initialization statement. like
for(let i=doAuth();false;i++)Also bounds all optimizer pass loops with MAX_PASS_ITERATIONS to prevent
infinite loops.