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

    <tr>
        <th>Summary</th>
        <td>
            Clamp vector factor when the max trip count is known
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            vectorization
      </td>
    </tr>

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

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

<pre>
    Currently, in `getMaximizedVFForTarget` in LoopVectorize.cpp, we add a constraint when tail-folding that the trip count (number of elements processed per loop iteration) we are working with must be a power of two in order for us to clamp the vector factor (number of vector elements processed per loop iteration when the loop is vectorised). If we know, for example, the maximum trip count is 7, it seems wasteful to still choose VF=16 or VF=vscale x 16. We would be better off clamping the value to be VF=8 or VF=vscale x 8 in that case, with the remaining element being ignored since we're tail-folding.

https://github.com/llvm/llvm-project/blob/27498e9942dbb8dd005588a03d6777088d2255ce/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp#L4718
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUk0-PpDYQxT-NuZS2BcWfhgOHzYyQIm1OGU3ONi4aZ42N7GLonU8fmSabnSSH5IIxUI9Xv3qWMZqbI-pF_ZOonzO58exD_6tcXkipWJaZ8vpb_7SFQI7tN4FPYByIJr8R_yLvZjHvpF-HwYcXGW7EosnTB1-8X19pZB_MO13GdU2FO4HUGiSM3kUO0jiGfSYHLI39NHmrjbsBz5KBZwIOZoXRb45BYOu2RVEAPwFZWshxhDX4kWIkDSsFsN6vYJiCZOOdwO74XyDYffiahHfDMyxbZFAEEla_P_R498myD5oCTD7AFoE9jFYu62Hk7WgEJnksH7ycr_6TpbPXmc7n8aw2kbTA7gI_T8nyV-f3RCs5obtcVktpm-qWBHxbfiRjIlyPoTBEoiXCLiPTtNnUQmRjLYyz95HgdRDlc9GAD4_btzhKS3CHornAbwnTZnVCo4j56G56MHgMheBN2o2SrDrF2n9qtYnkMcFRxsP3QT2VB1qkcUnspAWK0s7cnA-kIRo3Euwk8BroQyQuIn8W-efHdWZeoyg_CxwEDjfD86Yuo18EDta-_bl8WoP_nUYWOCjrlcABr1XXUtdVqJVqtc7zum5bmZe6uV6vedtqxLoe6Qcdk-pegnRx8mGJAofvkRY4_EvEyy_VtWgz3Ze6KzuZUV9c87YpyrKts7mXZYWq1KhqpTUWTS3HRtWjajqti66uMtNjjlWOiEVVdVV96camK5t6UlioiRBFlSeK9pIsXny4ZSbGjfoWG2wyKxXZeBxlxDNb7-dpwHS6Q3-wUdstiiq3JnL8S4kNW-qfjtR_TPz33C7y_rfspbC6bAu2_99zOZwnqIf5PwIAAP__EOyI0Q">