[llvm-bugs] [Bug 34347] New: llvm doesn't generate inline sequence for load/store of unaligned atomic variable on x86_64

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 28 10:22:57 PDT 2017


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

            Bug ID: 34347
           Summary: llvm doesn't generate inline sequence for load/store
                    of unaligned atomic variable on x86_64
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: wmi at google.com
                CC: llvm-bugs at lists.llvm.org

-------------------- 1.cc -----------------------
#include <atomic>

struct AM {
  int f1;
  int f2;
};

std::atomic<AM> ip3{AM()};
std::atomic<AM> ip4{AM()};

void foo() {
  auto val = ip4.load(std::memory_order_relaxed);
  ip3.store(val, std::memory_order_relaxed);
}
-------------------------------------------------

~/workarea/llvm-r309240/dbuild/bin/clang -O2 -std=c++11 -fno-exceptions -S 1.cc
        .cfi_startproc
# BB#0:                                 # %entry
        pushq   %rax
.Lcfi0:
        .cfi_def_cfa_offset 16
        movl    $local_ip4, %edi
        xorl    %esi, %esi
        callq   __atomic_load_8
        movl    $local_ip3, %edi
        xorl    %edx, %edx
        movq    %rax, %rsi
        popq    %rax
        jmp     __atomic_store_8        # TAILCALL
.Lfunc_end0:
        .size   _Z3foov, .Lfunc_end0-_Z3foov
        .cfi_endproc


g++ -O2 -std=c++11 -fno-exceptions -S 1.cc
        .cfi_startproc
        movq    ip4(%rip), %rax
        movq    %rax, ip3(%rip)
        ret
        .cfi_endproc

If alignas(8) is added:
struct alignas(8) AM {
  int f1;
  int f2;
};

clang will generate inline sequence for the atomic accesses:
        .cfi_startproc
        movq    ip4(%rip), %rax
        movq    %rax, ip3(%rip)
        retq

-- 
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/20170828/55dff0b0/attachment-0001.html>


More information about the llvm-bugs mailing list