<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137040>137040</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
AArch64 SVE: Multiple ptrue instructions not merged
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MatzeB
</td>
</tr>
</table>
<pre>
SVE code operating with different vector types has a tendency to produce multiple `ptrue` instructions.
For example I got this from an internal user:
```
#include <arm_sve.h>
svuint32_t getSveVec(const uint32_t* inputPtr) {
svuint64_t vec = svld1uw_u64(svptrue_b64(), inputPtr);
svuint32_t clzV1 = svclz_u32_x(svptrue_b32(), svreinterpret_u32_u64(vec));
return clzV1;
}
```
Producing something like this:
```
$ clang++ -target aarch64-redhat-linux-gnu -march=armv9-a+sve2+fp16 -O3 -S -o - dup2.cpp
...
ptrue p0.d
ld1w { z0.d }, p0/z, [x0]
ptrue p0.s
clz z0.s, p0/m, z0.s
ret
```
My understanding is that a `ptrue p0.b` would suffice here and in fact GCC is producing that code.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVF1v6ygQ_TWTl5EtAo6TPPghaZvVPlR7pUp9jTBMbPZibPHhtvn1K9z0Nnt1o0iDgXPgnJlBhmA6R9TA5gibx5VMsR998yzjlY6rdtQfzcvrE6pRE44TeRmN6_DNxB61uVzIk4s4k4qjx_gxUcBeBpQYyWly6gPjiJMfdVKEQ7LRTJYQajZFnwhqhsaF6JOKZnShBHYAdjiNHuldDnnr39iNEWNvAl78OKB0aFwk76TFFMiDyAio2e3PDsCFccomTQjiQfrhHGYqexBPwA5hTsZFwc8RO4ovM72SAr5TowsRv5aAH9C4KcUf0QPfI2yPwA6IiJ_wujovmhHEI4bZ6nV6O6e6Ar4L8yLs3C5fwPfAH-65QCxUd9dQ9vq6vjEpez0nwc_v90yCfzOF2dMif_IUl62fx85Zxf6b31NM3n1yf07B9vE3n34sWcnZDONAsc8ja37SYvafbK1QWek64EfgRyyi9B1FlNKrvq4KT7qXsbDGpfeicwmLIa-AeJR-mPeFBH4MM3Hgx8u0rrH4R2DxgsWIBeo08VJNE7BDWZY3r_NvsSBHVuq7aavXbznC9ohXVmrM6vgDTgz46ZpHsDm-M9hkzfck4Y5E2esSr3n6Czzk0fX_Gz3F37x4_sDkNPkQpdPZNxMw9jKi_FXa-bQ21_fbmKzGkC4Xowh78oTSaTQOL1JF_OvhIaOnX8lYeHK7lSvdCL0Xe7miZr2tNpWoas5XfbOpFdc1V4LL3faiq7ratVQzVddM7Nu2XpmGM75hFRfr3WbLeMl3WtGl3cpdpZiQa6gYDdLY0tp5KEffrUwIiZq12LKKraxsyYblSeC8leonOQ3icDgsqQbO80vhmwwu2tQFqJg1IYZvumiipeYGwJfXJxAHfP7q_0-H7jsf3RhxIN-RXiVvmz7GaSlCfgJ-6kzsU1uqcQB-ymfcQjH58V9SEfhpuX8AfrpJmBv-XwAAAP__yT9_0g">