<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LoopIdiomRecognize can turn infinite loops into countable loop using ctlz"
   href="https://bugs.llvm.org/show_bug.cgi?id=37479">37479</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LoopIdiomRecognize can turn infinite loops into countable loop using ctlz
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>craig.topper@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>On targets that support ctlz, loop idiom recognize can transform code like this

int foo(int x) {
  int cnt = 0;
  while (x) {
    x >>= 1;
    ++cnt;
  }
  return cnt;
}

Into just returning (32 - ctlz(x)). Or if the loop contains other code it will
create a loop that runs (32 - ctlz(x)) times.

But if x was negative the original code would have been an infinite loop since
the shift would just keep copying the sign bit preventing x from ever being 0.


This transform was added by D32605 and the motivating case cited there looks
pretty much like above with an additional "if (x < 0) x = -x;" before the loop.

Ideally I'd like to not lose the optimization. Are there any things we can
exploit to ensure this is safe for that motivating case.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>