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

            Bug ID: 42358
           Summary: Bad code generation for __builtin_clrsbl
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

When compiling this code :

int clrsbl(unsigned long x)
{
    return __builtin_clrsbl(x);
}

Clang generates really bad code on several backends (x64, x86, RISCV-32,
RISCV-64), such as (on x64)

  mov eax, 64
  add eax, -1

or (on RISCV-32)

  addi a0, zero, 32
  addi a0, a0, -1

This bug, however, is not present on certain backends such as WebAssembly or
PowerPC 64 (le and not le)

I looked at the emitted llvm code, and I think this is probably an optimization
problem related specifically to @llvm.ctlz. It looks like it's expanding ctlz
after the passes that would eliminate the bad code.

Link to see examples of this across backends : https://godbolt.org/z/pbBKgD

I filed this as an x86 backend bug because I do not know how to file a bug for
several backends at the same time

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to