<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92366>92366</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV][LoopUnroll/CostModel] Loops with Insert/Extract element using induction variable without vector are not unrolled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
joe-img
</td>
</tr>
</table>
<pre>
Without vector, extractelement/insertelement with non-constant index can be very costly.
This was factored into the cost model in https://github.com/llvm/llvm-project/pull/67334
However, in the case of full canonical loop unrolling and the index being the induction variable, the index _will_ be constant, but is not at the time of estimating the cost of unrolling the loop.
Example before and after this change: (llvm 17 vs 18)
https://compiler-explorer.com/z/Mh6eWKjr7
I had a go at fixing this myself, but could not see a good fix. I ended up abusing ephemeral values that get passed into UnrollCostEstimator.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUU01vpDgQ_TXmUkoL3DTQBw6ZJGij3bns1xxHBhfgyLiQXXR39tevbKaVrPY0l27Z9Vz13qOeCsFMDrEVpy_i9JypjWfy7Rvhg1mmrCf93n4zPNPGcMGByQv5BHhjrwZGiws6FrIzLqC_n-FqeAZH7mEgF1g5BuM03mBQDnqEC_p3GCiwfT-AyJ9F_vjnbAJcVYBRxRmowTgm4BkTEBbSaME4mJnXII6PQnZCdpPheesPAy1CdtZe7n8Pq6c3HCKzdbNWyK6qj8dyn7X__kJXvGBSY9w-SAUEGmHcrI1UyZlBWbBEK2zOk7XGTaCcTuhdUY_x7sd5G9iQg4vyRvUWY-sP5PersfZ7lH83Jdb7jcEEcMSgOKHZLIkFBjaL4nv75AKNn4jE28jt8FnVy00tq0XocSSPiawaGT1wNHiYlZtQHB9ByCb6BEUNlwBFI-R5b_BffwdaVmPRP-BtteTR_7D6HyG7r3OF33598_Xn-a8wKw0KJop6RnPbmZoAy3tAO941D7RZnWQHxIQnHeEHeAV0GjVsK6h-C_E9rjMu6JWFi7IbBuBZMUzIsKoQ7rvyV3LmiQK_7NaRP2S6Perz8awybIu6ODVlc5ZlNrf6WCmpT7oqz0Vflc1Y1UXd1zpv-kHlRZmZVuayzE9FlTelzMuDwrqspTwPZ2yKopGizHFRxh6ijwfyU2ZC2LA9y2NVZVb1aEMKlZQOr5CKQsqYMd-mHe23KYgytyZw-OjChm1K4--vfzz9LU7P4vTlN6J1lydkFxV-jXEQp2eIlbDn7TVFUMjuZQ8n3NO4m_j__UzPPnINymP6IvuKoc42b9ufzlsSGoTskhH_BgAA__8hPXoN">