[LLVMbugs] [Bug 16115] New: {32, 64} - __builtin_clz{, l}(...) does not get optimized correctly on x86.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 22 14:55:54 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16115

            Bug ID: 16115
           Summary: {32, 64} - __builtin_clz{,l}(...) does not get
                    optimized correctly on x86.
           Product: new-bugs
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: bigcheesegs at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130522/1c462ce6/attachment.html>


More information about the llvm-bugs mailing list