llvm-project
llvm-project copied to clipboard
[AArch64] Missed MADD folding opportunity (MUL + shifted-register ADD)
For the following function,
int f(int a, int b, int c) {
return a*b + (c>>2);
}
LLVM currently generates:
f:
mul w8, w1, w0
add w0, w8, w2, asr #2
ret
We could generate the following instead:
f:
asr w8, w2, #2
madd w0, w1, w0, w8
ret
The ASR + MADD is more efficient than MUL + shifted-register ADD for some CPUs (e.g., Neoverse V2). This pattern shows up in benchmarks such as x264.
@llvm/issue-subscribers-backend-aarch64
Author: pzhengqc
For the following function,
```
int f(int a, int b, int c) {
return a*b + (c>>2);
}
```
LLVM currently generates:
```
f:
mul w8, w1, w0
add w0, w8, w2, asr #2
ret
```
We could generate the following instead:
```
f:
asr w8, w2, #2
madd w0, w1, w0, w8
ret
```
The ASR + MADD is more efficient than MUL + shifted-register ADD for some CPUs (e.g., Neoverse V2). This pattern shows up in benchmarks such as x264.
Hi, I'm interested in picking this up if you're not planning to work on it right away.
6. Hi, I'm interested in picking this up if you're not planning to work on it right away.
Thanks for the help, @StarOne01. I have already started working on the fix.