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

Reply via email to