cfallin commented on issue #1172:
@abrown is this still an issue with the current backend? (Doing some issue gardening at the moment)
abrown commented on issue #1172:
No, I think this is resolved by the current
emit.rs
code ofInst::ShiftR
:
abrown closed issue #1172:
What is the feature or code improvement you would like to do in Cranelift?
As described in https://github.com/WebAssembly/simd/issues/117#issuecomment-573494583, Wasm shifts do extra runtime work to ensure the shift value is within a certain range. This is extra work that could be removed if we had knowledge that the shift value was constant and in the required range. This knowledge could also be used to lower the Wasm shifts to instructions using an immediate.
What is the value of adding this in Cranelift?
Emit faster code.
Do you have an implementation plan, and/or ideas for data structures or algorithms to use?
I think this type of optimization may apply to more than just Wasm shifts so I hope this approach works for those as well:
- add an
is_constant(v: Value)
function toDataFlowGraph
; initially this could check if the value passed was created by one of the following instructions:iconst
,fconst
,bconst
,vconst
. This could get more complex later but I feel this simple implementation would be a good start.- in
code_translator.rs
, check if the shift valueis_constant
and if it also inside the expected range (e.g. 0-31), lower the Wasm shift toish*_imm
; otherwise, lower toish*
as is done currently.Have you considered alternative implementations? If so, how are they better or worse than your proposal?
No, open to suggestions.
Last updated: Nov 22 2024 at 17:03 UTC