https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103090
Petr Skocik <pskocik at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pskocik at gmail dot com --- Comment #3 from Petr Skocik <pskocik at gmail dot com> --- Tangentially related: Gcc and clang both kinda do badly with inline assembly equivalents of these (locked or unlocked) too. If you "output" a particular flag and test that, the codegen is great but if you try to say "flags are set according to the result" (rather a common thing in x86(-64)) with something like asm("lock incl %0" : "+m"(*X), "=@ccz"(zf), "=@ccs"(sf)); if ( zf!=(*X==0) ){ __builtin_unreachable(); } if ( sf!=(*X<0) ){ __builtin_unreachable(); } and then immediately afterwards try to do with-0 comparisons against *X, then a reload and a test/0-compare will be generated even though a smarter compiler could just pick up on the flag assertions and avoid the reload and test/0-compare: https://godbolt.org/z/7e8PKhTjY