<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64294>64294</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [sve] gcc generate better code for a search loop
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zhongsir1
      </td>
    </tr>
</table>

<pre>
    test: https://godbolt.org/z/qjzhsY8c1
```
int s331(void)
{
// search loops
  int j = -1;
  for (int i = 0; i < LEN_1D; i++) {
    if (a[i] < (real_t)0.) {
      j = i;
    }
  }
  return j+1;
}
```

* gcc: generate a sve loop
```
.L2:
 punpkhi p7.h, p15.b
  punpklo p5.h, p15.b
  ld1d z31.d, p7/z, [x4, x0, lsl 3]
  ld1d z28.d, p5/z, [x2, x0, lsl 3]
  fcmlt p14.d, p6/z, z31.d, #0.0
  add x0, x0, x3
  fcmlt p7.d, p6/z, z28.d, #0.0
  uzp1 p7.s, p7.s, p14.s
  and p7.b, p7/z, p15.b, p15.b
  whilelo p15.s, w0, w1
 clastb s29, p7, s29, z30.s
  incw z30.s
  b.any .L2
```

* llvm:
```
.LBB0_1: // =>This Inner Loop Header: Depth=1
  ldr d0, [x10, x8, lsl #3]
  fcmp d0, #0.0
  csel w9, w8, w9, mi
  add x8, x8, #1
  cmp x8, x11
  b.ne .LBB0_1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VM9vtDYQ_WtmL6MgewwLHDiE8K1aKeqpl54iA87i1AsUe7Pft399ZQP7K2klBDYz7_H8Zhhprd73ShWQlJBUG3l03TAV527o91ZPfFMP7a_CKetAPGPn3GhBPAPtgHb7oa0H46Jh2gPtzkC7fz7Onf0raziwCtgzbNlyha3uHVohOFD2OegWKF_S0nJZBFq0Sk5Nh2YYRjsHED32A0FU-MRBlOvr92FCoMxHdYgyEGVYvuDrjz_eeBX2QGW4crx8CxFRv3uwhKTUkFQBBJRNSpo3B5Sz6AsCFxH6RgMipNW6uVlOyh2nHj-AyqvkS_zBm9WAZ9w3jbd6r3o1SadQov1UwYxvgdEr-YLM3xyP_fh3p3FMow7oBUeeRPWqJwTNgGPyTdC0vMWz4FEbQulc0BeEpPwZ-8VP5u_GGhSQVPcwyhZYcguj_4a9NwfjcOTxgtuuuIsCIMEitubLtl2Ylrt4YEq_EK2a7omO55H7bDufcnnyOLo0muxbH6jvbZi9ejTt1GmjvKM8mZlOQd1paX9sjLSuRkv5yvaybs6CRTfN3Zzu39SR7H-hr-3_N4sxn4dL-b90RlmyN-6bafmxQFQgfvzZaYu_972a8HUYRvxNyVZNPq1So-tAVPxa3glbthaUz95na0WBxENRxzX7zvTGKoOncOxTAM_rg74rb3YlBxIXCZ50iXF-tadXuJ7v_uybthBtLnK5UQXf5ixLKWVi0xVpw5P3tI7zLM1FQqqOJWcsF3UjamKKbXRBjATLGGfbhMcioozltWxIpk2e5gmDmKmD1Cbyrvupt9HWHlWxjSmPN0bWytgwR4l6dcIQBCI_VqfCY57q495CzIy2zl5ZnHYmDGD7qfwc2jfN9fevlXNqwmZoVZh28nY8bo6TKR6GsnbdsY6a4QC0C-0xP57GafhQjQPaBWEWaBeE_xsAAP__6MSU9A">