<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - {32, 64} - __builtin_clz{,l}(...) does not get optimized correctly on x86."
   href="http://llvm.org/bugs/show_bug.cgi?id=16115">16115</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>{32, 64} - __builtin_clz{,l}(...) does not get optimized correctly on x86.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bigcheesegs@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>unsigned foo(unsigned i) {
  return 32 - __builtin_clz(i);
}

Is compiled to:

  bsrl    %edi, %eax
  xorl    $-32, %eax
  addl    $33, %eax
  ret

I expect:

  bsrl    %edi, %eax
  ret

Which is what this produces:

unsigned foo(unsigned i) {
  return __builtin_clz(i) ^ 31;
}


I believe the issue is that the optimizer doesn't know that bsrl will never
result in a value greater than 31 and thus there's no need to worry about wrap
around.</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>