https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107456
--- Comment #2 from Marko Mäkelä <marko.makela at mariadb dot com> --- Sorry for the noise. I posted a variant of the program to https://github.com/llvm/llvm-project/issues/58685 and g++-12 is already emitting the optimal code. Example: #include <atomic> bool lock_add_sete(std::atomic<uint32_t> &a, uint32_t b) { return 0 == b + a.fetch_add(b); } 0: f0 01 37 lock add %esi,(%rdi) 3: 0f 94 c0 sete %al 6: c3 ret