dim added a comment.

There's still something strange here.  If I compile the following on 
i386-freebsd12, with `clang -march=i486 -O2 -S`:

  _Atomic(long long) ll;
  
  void f(void)
  {
    ++ll;
  }

the result is:

        .globl  f
        .p2align        4, 0x90
        .type   f,@function
  f:                                      # @f
  # BB#0:                                 # %entry
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %ebx
        movl    ll+4, %edx
        movl    ll, %eax
        .p2align        4, 0x90
  .LBB0_1:                                # %atomicrmw.start
                                          # =>This Inner Loop Header: Depth=1
        movl    %eax, %ebx
        addl    $1, %ebx
        movl    %edx, %ecx
        adcl    $0, %ecx
        lock            cmpxchg8b       ll
        jne     .LBB0_1
  # BB#2:                                 # %atomicrmw.end
        popl    %ebx
        popl    %ebp
        retl
  .Lfunc_end0:
        .size   f, .Lfunc_end0-f
  
        .type   ll,@object              # @ll
        .comm   ll,8,4

So what gives?  It's still inserting a `cmpxchg8b`!  AFAIK it should now insert 
a call to `__atomic_fetch_add_8` instead.

Note that this changes if you use C++ atomics, e.g.:

  #include <atomic>
  
  void f(std::atomic<long long>& x)
  {
    ++x;
  }

compiles to:

        .globl  _Z1fRNSt3__16atomicIxEE
        .p2align        4, 0x90
        .type   _Z1fRNSt3__16atomicIxEE,@function
  _Z1fRNSt3__16atomicIxEE:                # @_Z1fRNSt3__16atomicIxEE
  .Lfunc_begin0:
        .cfi_sections .debug_frame
        .cfi_startproc
        .cfi_personality 0, __gxx_personality_v0
        .cfi_lsda 0, .Lexception0
  # BB#0:                                 # %entry
        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        movl    8(%ebp), %eax
  .Ltmp0:
        movl    %eax, (%esp)
        movl    $5, 12(%esp)
        movl    $0, 8(%esp)
        movl    $1, 4(%esp)
        calll   __atomic_fetch_add_8
  .Ltmp1:
  # BB#1:                                 # 
%_ZNSt3__113__atomic_baseIxLb1EEppEv.exit
        addl    $16, %esp
        popl    %ebp
        retl
  .LBB0_2:                                # %lpad.i.i
  .Ltmp2:
        movl    %eax, (%esp)
        calll   __cxa_call_unexpected
        subl    $4, %esp
  .Lfunc_end0:
        .size   _Z1fRNSt3__16atomicIxEE, .Lfunc_end0-_Z1fRNSt3__16atomicIxEE
        .cfi_endproc


https://reviews.llvm.org/D29542



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to