8000 Optimize divisions and remainders by constants. by sjrd · Pull Request #5167 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Optimize divisions and remainders by constants. #5167

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sjrd
Copy link
Member
@sjrd sjrd commented May 10, 2025

Needs more tests and benchmarks.

Also more references to sources, such as relevant papers.

sjrd added 5 commits May 10, 2025 14:57
As well as the IR version to 1.20-SNAPSHOT.
This allows to better mutualize their implementation with the
signed divisions.

Moreoever, our 3 implementation strategies (JS with `RuntimeLong`,
JS with `bigint` and Wasm) have different efficient implementations
of those operations. Using IR BinaryOps for them allows each backend
to use the most appropriate implementation, while letting the
optimizer generically manipulate their mathematical properties.
Now that we have the tools to perform the division by
multiplication and shift, we can do it with the hard-coded
`Strategy`.

This also allows to remove the hackish way of reusing
`unsignedDivModHelper` to compute `toString()`.
Previously, we had various places in the linker that special-cased
division by non-zero constants to consider them pure.

Now that the optimizer systematically rewrites all such divisions
into multiplications and shifts, these special-cases are
effectively dead code, so we can remove them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0