[llvm-bugs] [Bug 46434] New: Failure to recognize table-based ctz implementation

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 24 04:45:50 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46434

            Bug ID: 46434
           Summary: Failure to recognize table-based ctz implementation
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

int f(unsigned x)
{
    static const char table[32] = {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15,
25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
    return table[((unsigned)((x & -x) * 0x077CB531U)) >> 27];
}

This can be optimized to `__builtin_ctz(x);`. This transformation is done by
GCC (or at least https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838 claims to
do so, though I can't get it to trigger), but not by LLVM.

-- 
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/20200624/741907c6/attachment.html>


More information about the llvm-bugs mailing list