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

    <tr>
        <th>Summary</th>
        <td>
            Should we have a llvm.loop.optsize/minsize attribute
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            enhancement
      </td>
    </tr>

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

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

<pre>
    This stems from the discussion in https://github.com/llvm/llvm-project/pull/159522. That PR aims to use PGOForceFunctionAttrsPass (added in https://github.com/llvm/llvm-project/pull/69030) to prevent SimpleLoopUnswitch from increasing the code size of cold functions. 

Is it worthwhile to have a loop-level equivalent, something like PGOForceLoopAttrsPass that annotates cold loops with a `llvm.loop.optsize` attribute or equivalent?

We have the llvm.loop.unroll.disable attribute for LoopUnroll, but this would be more general. Just from a quick grep in llvm/lib/Transforms/Scalar it looks like LoopUnroll, SimpleLoopUnswitch, LoopBoundSplit, LoopLoadElimination and LoopIdiomRecognize could take advantage of this to get more granular behaviour.

cc) @aeubanks
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVM2OpDYQfhpzKS1ym6Z_DhxmkxBttFJGOxPlXNgFOG1s1i53K3n6yPTMzkZzivaEKKH6_uoDU7KTJ-pE-1G0P1eYeQ6xc_lC7nyshmD-7p5nmyAxLQnGGBbgmcDYpHNKNniwHmbmNYnmQaheqH6yPOeh1mERqnfu-vr4sMbwF2kWql-zc0L1u_bcKlXD84wMj18A7ZKAA-RE8Pjr732ImvrsNdvgH5hjesSUQKgTGkPmR5APZ9lIoc4FbY10Jc_wZJfV0ecQ1j98ulnW812v9ToSJuunTboOhiDZfwjCCDo4A-MLxVSDkA9CPnxKYBluIfJ8m62jgjLjlQDBhbB-cHQlB_Q12ys68izUT5DCQjwXEGcvb_ILnTfpXIxC7wMjU7qjl40JbpZnQBAHWQTXZViHlQtPcZCAzNEOmQlC_B646e-M_6Q7wSLwbUH2MThXG5twcPTdkjFEuBtVPij0h8zA5VBuITsDA8ESIsFEniK6Gn7Lie92InzNVl9girSWCF9zsoNQ_XNEn8YQlyRU_6TRYSxWuhAu6W7Mf2HfZ1am5f1jyN48rc7y6-RzQPOLs4v1WNIC9GabfzI2LF9Ih8mXVPUmgPFCgOaKnnHaot7UcYCJ-EVbRJ8LwYFmvNqQY303U-tyWWIvkfKA_pIq0zXm3Jyxom53bE9qJ_fHppq74XAg2Uo6tfo0jESjwrGRcmxb3bTDaaxsp6Rq5Xl32rX7Y9vUaMwR5a7ZmbaRDZ3EXtKC1tVbaiFOlU0pU1eqdW4rhwO5tLVbKfIzek3LdnGq1D12Wz2GPCWxl84mTm-L2LKj7mne_LjRtwt-d1-qX6zfGvHtQqocXfe_y7lRTy8_hnNbXTv1bwAAAP__hyOZDg">