[LLVMbugs] [Bug 10192] New: Defining 0 for clz does not optimize

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jun 25 05:34:54 PDT 2011


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

           Summary: Defining 0 for clz does not optimize
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: ARM
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: xocotl at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Howdy... GCC leaves __builtin_clz undefined for zero, so writing code in Clang
like

return 31 - (value == 0 ? 32 : __builtin_clz(value));

You would think the 'value == 0 ? 32 : ' would get optimized out, since CLZ on
ARM is defined as 32 for value 0. However that does not appear to be the case.
On Thumb 2 I get the following output for the above snippet:

00000000 <uint32_log2_floor>:
   0:    2120          movs    r1, #32
   2:    2800          cmp    r0, #0
   4:    bf18          it    ne
   6:    fab0 f180     clzne    r1, r0
   a:    f1c1 001f     rsb    r0, r1, #31    ; 0x1f
   e:    4770          bx    lr

It would be nice if LLVM could recognize this situation, where the branch is
identical to the defined behavior for the CPU instruction.

Thanks

James

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list