Skip to content
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

Replacing integer division by a power of 2 with an arithmetic shift or logical shift #574

Open
qjivy opened this issue May 9, 2022 · 0 comments
Assignees

Comments

@qjivy
Copy link
Collaborator

qjivy commented May 9, 2022

In builtin StoreFastElementIC_Standard, following code snippet will be generated:

0x7f18e20f0054  e194  00800693       li        a3, 8   
0x7f18e20f0058  e198  fb843703       ld        a4, -72(fp) 
0x7f18e20f005c  e19c  02d74733       div       a4, a4, a3

The code is from a code-assembler API, IntPtrDiv code gen from here and the lowered into Sea-of-Node machine operator Int64Div, which finally lowered by instruction selector into Div64.
But as the code snippet shows, one of its operand, or say the divider, is a constant 8, so we can use shift right to get the same result. It's a strength reduction optimization.

We can check and make the optimization.

@qjivy qjivy self-assigned this May 9, 2022
@qjivy qjivy removed their assignment Jun 14, 2022
@AlviseDeFaveri AlviseDeFaveri self-assigned this Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants