<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84152>84152</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64] there is redundant neg instruction for mull with complex type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vfdff
</td>
</tr>
</table>
<pre>
* **test**: https://gcc.godbolt.org/z/enYjsjGfE
```
define ptr @_ZNSt7complexIiEmLIiEERS0_RKS_IT_E(ptr noundef nonnull align 4 dereferenceable(8) %a,
ptr noundef nonnull align 4 dereferenceable(8) %b) align 2 {
entry:
%0 = load i32, ptr %a, align 4
%1 = load i32, ptr %b, align 4
%mul = mul nsw i32 %1, %0
%_M_imag = getelementptr inbounds i8, ptr %a, i64 4
%2 = load i32, ptr %_M_imag, align 4
%_M_imag.i = getelementptr inbounds i8, ptr %b, i64 4
%3 = load i32, ptr %_M_imag.i, align 4
%mul3 = mul nsw i32 %3, %2
%sub = sub nsw i32 %mul, %mul3
%mul6 = mul nsw i32 %3, %0
%mul9 = mul nsw i32 %2, %1
%add = add nsw i32 %mul6, %mul9
store i32 %add, ptr %_M_imag, align 4
store i32 %sub, ptr %a, align 4
ret ptr %a
}
```
* **llvm**: transform the madd into fmls, then the **neg instruction** is redundant
```
std::complex<int>& std::complex<int>::operator*=<int>(std::complex<int> const&): // @std::complex<int>& std::complex<int>::operator*=<int>(std::complex<int> const&)
ldp w11, w8, [x0]
ldp w10, w9, [x1]
mul w12, w9, w8
mul w8, w8, w10
madd w8, w9, w11, w8
neg w13, w12
madd w9, w10, w11, w13 ; w9 = w10 * w11 + w13 = w9 = w10 * w11 - w12 = w10 * w11 - w9 * w8 = fmls w10 * w11, w9, 28
stp w9, w8, [x0]
ret
```
* the IR is simlplied from https://gcc.godbolt.org/z/fPnnxGhb3
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.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