Skip to content

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

@qjivy

Description

@qjivy

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions