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

    <tr>
        <th>Summary</th>
        <td>
            Any option that enable loop inversion?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Are there any options that enable loop inversion?  More specifically,can LLVM transform the while form loop into do-while form loop as the following.

Before the transformation, the code is:
`
void foo(unsigned a, unsigned& ret) {
  bool undone = true;
  #pragma unroll 4
  while((a > 0) && undone) {
    ++ret;
    if(ret > 2)    undone = false;
    if(undone)   --a;
  }
}
`

After the transformation, the code is:
`
void foo(unsigned a, unsigned& ret) {
  bool undone = true;
  #pragma unroll 4
  while((a > 0) && undone) {
    ++ret;
    if(ret > 2)    undone = false;
    if(undone)   --a;
  }
}
`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzslL1u4zoQhZ9m1AxsUEPrr1Bhx1GVtLenpaHFC5o0SCpB3n4h2kmMLLDVlttQJEfnm6MDYVSM5uyYe6gOUB0LtaTZh566ble2tShFcfLTR78PjGnmwKjcB_prMt5FTLNKyE6dLKP1_orGvXGIxjuQA-KrD4zxyqPRZlTWfsDzAIcnaJ9G5fDl5b9XTEG5qH24rHR8n41lzMc7Lnmc_ObnvYr5de2t9e_GnbcgjiD2t_XA2t_cftPV6hfoKd-OfmI0EeRdALW4bd68mVB7D9QuLscyoVpVnyegGgMnoA6hOdxEiCfvLS5u8o4R5BFTWBjkVxlIXoM6XxQuLnhrcfdZyZ8F1AK1CkE-o8hkqtc-N-CPVivtAHRYTciHW6OB2sApU2gVIT5a0spG_l3x3QNxs1GPppvjPZyvzWdKt3WvE4d_If_9kIupl1MnO1VwX9ZNSQ3VoinmXu60rITe6ZFG2fBY6VG3QpeirErWbVuYngRRSWVTCpJUb6eubZpK1mqUE9Wqg53gizJ2a-3bZevDuTAxLtxXXVVXhVUntjHPASLH75iLQLSOhdCvms1pOUfYCWtiit-UZJLlfv81GP48F4ol2H5O6Zp_DhqAhrNJ83Lajv4CNKzY-2NzDf5_HhPQkM1EoCGb_RUAAP__SxVhkw">