| Issue |
76307
|
| Summary |
[AArch64] `add` and `mul` not replaced by `madd/msub` when branching on result
|
| Labels |
backend:AArch64,
missed-optimization
|
| Assignees |
|
| Reporter |
Kmeakin
|
Usually code of the form `x * y + z` is compiled to `madd`. But if branching on the result, clang instead emits a pair of `mul` and `subs`:
# C code
```c
uint32_t msub0(uint32_t x, uint32_t y, uint32_t z) {
if (x * y - z == 0) {
return f();
} else {
return g();
}
}
uint32_t madd0(uint32_t x, uint32_t y, uint32_t z) {
if (x * y + z == 0) {
return f();
} else {
return g();
}
}
```
# Resulting assembly
```asm
msub0:
mul w8, w1, w0
cmp w8, w2
b.ne .LBB0_2
b f
.LBB0_2:
b g
madd0:
mul w8, w1, w0
cmn w8, w2
b.ne .LBB1_2
b f
.LBB1_2:
b g
```
# Optimal assembly
```asm
msub0:
msub w0, w0, w1, w2
cbnz w0, .L6
b f
.L6:
b g
madd0:
madd w0, w0, w1, w2
cbnz w0, .L6
b f
.L6:
b g
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs