<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94546>94546</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Regression in code quality for horizontal add after 70a54bca6f
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dyung
</td>
</tr>
</table>
<pre>
We have an internal test which tests whether the compiler generates horizontal add instructions for certain cases. Recently we noticed that one of the cases, the code generated seems to have gotten worse after a recent change 70a54bca6f.
Consider the following code:
```c++
__attribute__((noinline))
__m256d add_pd_004(__m256d a, __m256d b) {
__m256d r = (__m256d){ a[0] + a[1], a[2] + a[3], b[0] + b[1], b[2] + b[3] };
return __builtin_shufflevector(r, a, 0, -1, -1, 3);
}
```
If compiled with optimizations targeting btver2 (`-S -O2 -march=btver2`), the compiler previously generated the following code:
```
vhaddpd ymm0, ymm0, ymm1
ret
```
But after 70a54bca6f, the compiler now is generating worse code:
```
vextractf128 xmm1, ymm1, 1
vhaddpd xmm0, xmm0, xmm1
vinsertf128 ymm0, ymm0, xmm0, 1
ret
```
@alexey-bataev, this was your change, can you take a look to see if there is a way we can avoid the regression in code quality in this case?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVM2OozgQfhpzKSUCA4EcOGx3FGlPK80e9hgVUIB3jJ21C9KZp18ZSHd6ZnY1yLKxXT_fV1Uu9F71hqgS-YvITxFOPFhXtffJ9FFt23v1F8GAMwEaUIbJGdTA5Blug2qG5dfDbSAeyAEPBI0dr0qTg54MOWTyMFinvlnDqAHbFpTx7KaGlTUeOuugIceoDDToye_hCzVkWN_hRmAsq4Za4AEZrCGw3eoliAr5urls6d1dC55o9MB2Bd5bZjJws84TYMfkAMEtLqAZ0PQERYx5Vjd46PYiPon4t3V-tcardqPVWa3tTZl-8SbSTUYc4nU0Qr6EsZxeLsjsVD0xXS5ClkKWxi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