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: unassignedb...@nondot.org
          Reporter: gabrav...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to