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

    <tr>
        <th>Summary</th>
        <td>
            bad RVV code generation with `-fvectorize`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V
      </td>
    </tr>

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

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

<pre>
    Reduced test case from XNNPACK:

```
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <iostream> 
 
bool z{true};
size_t a{1};
uint32_t b{1};
uint32_t c{1}; 
 
inline size_t select() {
  if (z) return (a + b - 1) / c;
  return (a - b + 1) / c + 1;

 
void __attribute__((__noinline__)) test() {
  int8_t input[100];
  int8_t max_value = 0; 
 
  for (size_t c = 0; c < 3000; c++) {
    for (size_t py = 0; py < 15; py++)
      max_value = std::max(max_value, input[select()]);
    __asm__ __volatile__("" ::"r"(max_value));
  }

 
int main(int argc, const char* argv[]) {
  auto start = std::chrono::system_clock::now();
  for (int i = 0; i < 500; ++i)
    test();
  auto end = std::chrono::system_clock::now();
  std::cout << "Elapsed time: "
            << std::chrono::duration<double>(end - start).count() << "s\n";
  return 0;
}
```

CC: @preames
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVF1v2yAU_TX2C0qETezED35InFaaJlVTJ1V7szCQhJVABDhb--t3sZ3YadOnWQjD_Tz3cKEx_K18FrxlgiMvnEeMOoF21hzRr6enH-vqe0TWEd5G-DLneBj9NiVSM9VygSJSUbU3VvrDMSIP9_TsYI02Xymd51zsvtBK47wVNERGvX74NcYo9B4tN962IlpuI7LpFU6-i9ojCqpkKm-l9iQFTfOlho2a22RSK6kFGkI7oQTzUbqK0gKBy2CK5A6B8D1IrfCt1WFLYdqgBs1Q0pmnj5CGXH2mhjMwC8aj4bC9mAO0W1xnIzmqa-q9lU3rRV13qFZ1rU2POUiKEC-c8h3I2q-gIqlPrY-yTYJxlG0n8Ab9kf6tz1S14Ui2CH_iB6GdsaGIgSE22oVlhQjG_Q4K6sYNio_up7fRv1tXKMn6zdV_9EUf4EE_heYlaxBDzKsySqtrodMjDBXDTCZwgFJ3rGv4n42iXqoLsykM1EeHle0E0wzFbaTQS_dPDogF2FKDe1hSu2cBHzM6XMYDhdDrID0D2B7glDDaegN1UutvK75ctLB2b86LY82UYa-9RJs_Q8UjwoH4gEGOpMuO86w_s55yecP52E2TWB0qofn_YhpdTRsKrAIYoPpB0ZMLD5Y8CtAG0bQL-m8wv5uetxYO02gw4KZtlAiPTroKkGc9nQBkDln19apck7soq3TI-Onu4un9vP9adnNVdaAX-BQeNOFiUSZ5ni1zkpEi5iXhBSlo7KVXomwoR88vL9AQ8A7uhRY9cvQHnlkEgWe7MzQwvLrvAnZxa1V58P7kusZ8hLEHw7aBYo6wUep8-c1O1vzuev9ROtcKB4tsRXISH8plhpdZvhC7HDcpTnLKVkuc5qyhrFhxSmJFG6FcGXoyTUH6CtRBxudvP6vZSyAn28ayTHGaJjhZJDmGyuYcF8uENQneccJStgAGBLS-mgc4c2P3sS07ZE27d6BU0nk3Kqlzcq-FKPubEEOXHYwtobATsMLjroqyK-EfzxTkaQ">