[llvm-bugs] [Bug 51589] New: Suboptimal codegen with __builtin_ctz (regressed in 12)

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 23 11:34:35 PDT 2021


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

            Bug ID: 51589
           Summary: Suboptimal codegen with __builtin_ctz (regressed in
                    12)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

unsigned long f(unsigned long long value)
{
    unsigned int result;

    if ((value & 0xFFFFFFFF) == 0)
    {
        result = __builtin_ctz(value >> 32) + 32;
    }
    else
    {
        if ((unsigned int)value != 0)
            result = __builtin_ctz((unsigned int)value);
    }

    return result;
}

LLVM 11 -O2
f(unsigned long long):                                  # @f(unsigned long
long)
        mov     rax, rdi
        shr     rax, 32
        bsf     ecx, eax
        or      ecx, 32
        bsf     eax, edi
        cmove   eax, ecx
        ret

LLVM12+ -O2:
f(unsigned long long):                                  # @f(unsigned long
f(unsigned long long):                                  # @f(unsigned long
long)
        test    edi, edi
        je      .LBB0_1
        test    edi, edi
        je      .LBB0_3
        bsf     eax, edi
        mov     eax, eax
        ret
.LBB0_1:
        shr     rdi, 32
        bsf     eax, edi
        or      eax, 32
        mov     eax, eax
        ret
.LBB0_3:
        mov     eax, eax
        ret


https://godbolt.org/z/M9q4d13nq

-- 
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/20210823/11c6ec5b/attachment.html>


More information about the llvm-bugs mailing list