-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wazevo: initial work on constant folding #1851
Conversation
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this really needs fuzzing yeah
internal/engine/wazevo/ssa/pass.go
Outdated
// The fixed point is reached through a simple iteration over the list of instructions. | ||
// Note: Instead of just an unbounded loop with a flag, we may also add an upper bound to the number of iterations. | ||
isFixedPoint := false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think I would suggest to see how much overhead costs will be added like by compiling zig stdlib binray and let's have a reasonable O(1) upper bound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even without an upper bound the pass seems to account for less than 1% CPU time against the Wasm library.
in terms of hard numbers, on my machine it compiles the wasm binary in about 7.02 seconds with the extra pass and 6.94-6.99 without
To be fair, that might not be surprising: e.g., if the wasm binary went through wasm-opt
it might be already minimized, and if it weren't, operations between constants may not naturally occur in a Wasm binary very often (after all, it's already a compilation target)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...in fact, I am not even sure how often this pass will be useful, I don't know how often we'll find cases in the wild. Anyway it's a useful playground for me...
Besides, other, related techniques such as constant tracking and constant propagation might still be beneficial, and the framework should be similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out what (silly) mistake I was making with my experiment with algebraic simplification (just add X, const1; add Y, const2 => add X, (const1+const2)
). This, together with const-fold adds a more significant overhead (~7.4); but that should also mean that it does make some difference. On a first quick look, the first largest functions in the zig stdlib were not significantly smaller.
constFold, no simplification
1809672
1358096
906528
constfold + simplification
1809668
1358092
906524
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff in the size(?) seems negligible to me even with simplification…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agreed (yeah that's size in bytes)
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
bee6f93
to
2686b57
Compare
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
Signed-off-by: Edoardo Vacchi <[email protected]>
I pushed some new simple substitutions extending nop elimination. Algebraic simplification need more research to be effective. Now rebased and running some fuzzing locally. |
Signed-off-by: Edoardo Vacchi <[email protected]>
closing for now as no significant benefit so far |
#1496
This implements an initial, simple constant folding pass for add/sub/mul for i32/i64/f32/f64.
It also implements a new case for
passNopInstElimination
where one of the args is const 0.