------- Comment #1 from adam at consulting dot net dot nz 2010-06-07 05:35 ------- Example-specific workaround discovered for global register variable pessimisation with recent versions of GCC:
void push_flag_into_global_reg_var(uint64_t a, uint64_t b) { uint64_t flag = (a==b); global_flag_stack <<= 8; __asm__ __volatile__("" : : : "memory"); /* ??? */ global_flag_stack |= flag; } Every version of GCC tested (including gcc (Debian 20100530-1) 4.6.0 20100530 (experimental) [trunk revision 160047]) produces similarly compact code: 0000000000400494 <push_flag_into_global_reg_var>: 400494: 48 c1 e3 08 shl rbx,0x8 400498: 31 c0 xor eax,eax 40049a: 48 39 f7 cmp rdi,rsi 40049d: 0f 94 c0 sete al 4004a0: 48 09 c3 or rbx,rax 4004a3: c3 ret Telling the compiler that memory may have changed between global register variable assignments seems to have coaxed the compiler into treating the global register variable as volatile. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44281