https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96189
Bug ID: 96189 Summary: Failure to use eflags from cmpxchg on x86 Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- bool f(unsigned char* addr, unsigned char old_val, unsigned char new_val) { auto old_val_cpy = old_val; __atomic_compare_exchange_n(addr, &old_val, new_val, 0, 0, 0); return old_val == old_val_cpy; } With -O3, LLVM outputs this : f(unsigned char*, unsigned char, unsigned char): # @f(unsigned char*, unsigned char, unsigned char) mov eax, esi lock cmpxchg byte ptr [rdi], dl sete al ret GCC outputs this : f(unsigned char*, unsigned char, unsigned char): mov eax, esi movzx edx, dl lock cmpxchg BYTE PTR [rdi], dl cmp al, sil sete al ret GCC could use the EFLAGS generated from cmpxchg, but it does not.