https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71599

            Bug ID: 71599
           Summary: An extra unrelated move when compiling
                    compare_exchange_strong
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jianjin2016 at fb dot com
  Target Milestone: ---

At high optimizations, for the code below:
bool cas(std::atomic<uint64_t>* target, uint64_t expected, uint64_t desired) {
return target->compare_exchange_strong(expected, desired);
}

Gcc gives (link: https://godbolt.org/g/wP8Ah8 ):
movq %rsi, %rax
movq %rsi, -8(%rsp)  -----------------------(Note this spurious move)
lock cmpxchgq %rdx, (%rdi)
sete %al
ret

However,
Clang gives (link: https://godbolt.org/g/UmUO7M ):
movq %rsi, %rax
lock cmpxchgq %rdx, (%rdi)
sete %al
retq


This extra and unrelated move will make a difference in our measurable
benchmark result.

Reply via email to