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
VM doesn't optimize division by constant (except powers of 2). #17547
Comments
Below is the relevant comment for the comparison: cc @fsc8000. |
Code is now:
It's about the same as when originally filed. This is a division by a constant different from -1, it shouldn't need the compare. It also shouldn't need to smi-untag the constant. Or the operand for that matter, keep it multiplied by two and clear the tag bit afterwards.
And also, if the modulo isn't needed (I know you do div/mod combining), division by constants can be optimized. |
For negative numbers doesn't the proposed code in original report produces results that are off by 1? |
Example code:
generates optimized code:
Two smi untags (one should be enough) and an idiv instead of an imul.
I assume the cmp is for detecting division by zero, which is also not necessary.
Apart from unnecessary overhead, you can also convert division to a multiplication with much better efficiency.
Better code could be (edx still reserved):
The text was updated successfully, but these errors were encountered: