On Fri, Jun 17, 2016 at 11:16:24AM +0300, Andrey Ryabinin wrote: > > I suppose instead we'd want something like: > > > > tmp = READ_ONCE(*ptr); > > if (tmp > val) > > tmp -= val; > > else > > tmp = 0; > > WRITE_ONCE(*ptr, tmp); > > > > In order to generate: > > > > xchg %rax,0xa0(%r13) > > mov 0x78(%r13),%rcx > > sub %rax,%rcx > > cmovae %r15,%rcx > > mov %rcx,0x78(%r13) > > > > however, GCC isn't smart enough and generates: > > > > xchg %rax,0x98(%r13) > > mov 0x70(%r13),%rsi > > mov %rsi,%rcx > > sub %rax,%rcx > > cmp %rsi,%rax > > cmovae %r15,%rcx > > mov %rcx,0x70(%r13) > > > > Doing a CMP with the _same_ values it does the SUB with, resulting in > > exactly the same CC values. > > > > FYI - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3507 (Reported: > 2001-07-01) >
I found this one when I was googling yesterday: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30315 But yes, it seems this is a 'known' issue.