llvm / llvm/llvm-project

[AArch64] Missed optimization for sdiv by const

Open
#195,078 2 comments 0 reactions 0 assignees View on GitHub
backend:AArch64 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently, aarch64 doesn't optimize sdiv by 3 as much as it could:
https://godbolt.org/z/oKWbdjhvz

@jayfoad pointed this out in this [issue](https://github.com/llvm/llvm-project/pull/189287#issuecomment-4343813987) that this can be:

```asm
sdiv3: // @sdiv3
mov w8, #21846
movk w8, #21845, lsl #16
smull x8, w0, w8
lsr x8, x8, #32
add x0, x8, x8, lsr #31 # since x>>63 is x>>32>>31
ret
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.