<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118731>118731</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Optimize foldings of repeated sorted values, if the reducer is distributive
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Rudxain
</td>
</tr>
</table>
<pre>
I go into [further detail here](https://github.com/Rudxain/bin-rle.rs)
I'm aware this optimization may be considered "too niche", but I believe it makes more sense for a compiler to do this automatically than for a human to explicitly use this algorithm at runtime.
I'm also aware of the fact that it would be unlikely for an optimizer to infer that a dynamically-generated list has all of its values sorted **and** that the set of unique values is small relative to the list length.
However, it's much easier to apply this optimization if the list contents are statically-known. Yes, the optimizer might prefer to do constant-folding, but if the list is big enough it might be better to fold at runtime, where this optimization shines
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VMGO6zYM_Br5QiRw5HizOfiQ10XQPRXorUfZoi12ZSkVqeSlX1_I9nZfi6InCzA5nBmOZJhpCoidar-p9q0yWVxM3a_ZfjcUqj7aZ_cOUwQKEkG138acxGECi2LIg8OEqn1T-tWJ3Fg1F6WvSl8nEpf7_RBnpa8bmtLXnsIuedwnVvqs6ouqL-9Kn2YwD5MQxBFDvAnN9KcRigFm84QeYYiByWJCC0priRECDQ6V1kr_BH0WeIcePeEdgQRm84EMc0wIjIERxpjAwBDnG3lMIBFsXKeZLHE2QoPx_gniTNiKXZ5NKJX4_eZpIPFPyLxxNH6KicTNYARSDkIz7v-hx3PcRMURxCGMZpCCL4XgI2Zvi7AcPH2gf65Dw6f4lSOFsRxKjwH7DGZeae4mDJiMoAVPLOBMYeTLJBKGu_EZGTgmWfy6KH0xwa6HFa4QYpTSkQP9kfGziRh4LlgJvRG6Y-FRqpdBHsMkbhP6c3zgHVNZAInSJ4Y5Dw7QMK30ze22WPrvndL4hTjEIBiEoTjF8rmI3UeIj7CH35ALfin_cmamyQncEo5_r7LkQ0yQ3Ri9pTB9puLHUcTQ0wQYYp7ckpIFp0foUWSFKu0_rLTAPErE_0MFOwrIle0ae27OpsLucGqa5qV90cfKdYe273Vzag69HsxgcWzH-nV8Pbd6eMG61xV1utbHg67bWutTfdwPZ9S1PZ_q5qDR6hd1rHE25Pfe3-d9TFNFzBm7w-H11Bwqb3r0vNxbrQM-YPlbbkT7VqWuNO36PLE61kU-f8EIicful81P2CzjEoaEN1xytYVnTcWy4tXJhDYPmIqZllgS9bmkpMrJd__zApTZ22d3S_F3HETp68KYlb5uku6d_isAAP__WIKTpw">