[llvm-bugs] [Bug 45055] New: Missed optimization std::atomic with 64bit struct

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Feb 27 23:17:21 PST 2020


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

            Bug ID: 45055
           Summary: Missed optimization std::atomic with 64bit struct
           Product: clang
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jvapen at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Logging for
https://stackoverflow.com/questions/60445848/clang-doesnt-inline-stdatomicload-for-loading-64-bit-structs

Code:
#include <atomic>

struct A {
    int32_t x, y;
};

A f(std::atomic<A>& a) {
    return a.load(std::memory_order_relaxed);
}

Expected assembly (by GCC):
f(std::atomic<A>&):
        mov     rax, QWORD PTR [rdi]
        ret

Assembly by Clang:
f(std::atomic<A>&):                     # @f(std::atomic<A>&)
        push    rax
        mov     rsi, rdi
        mov     rdx, rsp
        mov     edi, 8
        xor     ecx, ecx
        call    __atomic_load
        mov     rax, qword ptr [rsp]
        pop     rcx
        ret
        mov     rdi, rax
        call    __clang_call_terminate
__clang_call_terminate:                 # @__clang_call_terminate
        push    rax
        call    __cxa_begin_catch
        call    std::terminate()

This clang missed optimization only happens with libstdc++; clang on Godbolt
inlines as we expect for -stdlib=libc++. https://godbolt.org/z/Tt8XTX.

More details, see the stack overflow post

-- 
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/20200228/7bd9e9ec/attachment-0001.html>


More information about the llvm-bugs mailing list