<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116139>116139</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unwanted SLP vectorization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kmeakin
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/TaxEM3rxP
```c
u8 log10_u16(u16 x) {
u8 n = 0;
n += (x >= 10);
n += (x >= 100);
n += (x >= 1000);
n += (x >= 10000);
return n;
}
```
produces
```asm
.LCPI0_0:
.hword 9
.hword 99
.hword 999
.hword 9999
.LCPI0_1:
.hword 1
.hword 2
.hword 4
.hword 8
log10_u16:
dup v0.4h, w0
adrp x8, .LCPI0_0
ldr d1, [x8, :lo12:.LCPI0_0]
adrp x8, .LCPI0_1
cmhi v0.4h, v0.4h, v1.4h
ldr d1, [x8, :lo12:.LCPI0_1]
and v0.8b, v0.8b, v1.8b
addv h0, v0.4h
fmov w8, s0
and w8, w8, #0xf
fmov s0, w8
cnt v0.8b, v0.8b
uaddlv h0, v0.8b
fmov w0, s0
ret
```
with `-fno-slp-vectorise` it produces shorter code:
```asm
log10_u16:
and w8, w0, #0xffff
ubfx w10, w0, #4, #12
cmp w8, #99
cset w9, hi
cmp w8, #9
cinc w9, w9, hi
cmp w8, #999
cinc w8, w9, hi
cmp w10, #624
cinc w0, w8, hi
ret
```
It would be nice if LLVM could avoid vectorization in a case like this
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU2PozgU_DWPy1Mi-0EIHDh0TybSaHuklvbjOjLYBO8AjrBJsvPrV3wkdGi6JyjCTrlcr1zYsrBWH2qlEtg8w2bnidYVpkn-qJT4qWsvNfK_pHDuaMF_AtoD7Q9GpqZ0a9McgPa_gPZ_icvX735zeQW2A_Y0vkM2_LLhfxthaQ6c_Wh5CBS1PMQLUIywfR4IiIhthDWCv0MG_hu4RqDnDgaKLgj-167PGVD8CO1h3uPEd8xGubapsb6BsN3NcngbzrExss2UnVGErQZk_fLl9Rv7wbrQbzW6Z12cTSMxXkQx_hBfHohvA2NB_lFB5MswLcLBMjka4GkbzIvJ9ti3J7YOCqAveB5TQyGbfugSdfAtnrvZpWwGFd5xYPM8kMF_Kg0n8KdUN7vPZGdLzapC35maOrzrvPPwu_p8qj8-opbXdUfpWGLs8K5zNStPHatgk4s7mbwyPeHc17VsucgwOryBfHbJl1UsG3n3adRuyerAaYWU5emNw9vI3CFbctgo98mZOWtXIIRslddmZcvj6qQyZxptFYQMtcProUJbmMapBjMj1W2PvT9kC_twlhGbMsrzWUxtml96Kmd33GBs-fVoZNXxjSaQPz-MmVV9pue4IxR6vv3m06-6us6maY9Oflf8qhI9oMKviwwp-ECGTZvrJvP5d_3m8GzaUmKqsNaZQp3jy8s_3zHrUXEyWuL4rX8Jp02NukaBmbAKS_1ToSu09WTiy9iPhacSvvX5Jgi3fuAVSRSHRKSkDHjox4xkvKWQSZlnvqRtvvF0QowCznnAOCcerIM02MacREacsSDfQsBUJXS5LstT1V17nra2VQnnIfdjrxSpKm1_fxJV2lolV-bodDW6BaLuYm2SbvoqbQ8WAlZq6-wk6LQrVfJ3fRa1UxL_fHm9X7HXNuX8GtauaNN1ZiqgfSc0NqtjY_5VmQPa9zYt0H50ekro_wAAAP__k8UCVA">