This testcase: int test (double a) { return __builtin_signbit (a + 1.0); } produces quite non-optimal code when compiled with '-O2' (-fomit-frame-pointer): test: subl $12, %esp ! xorl %eax, %eax ! movl $1072693248, %edx ! movl %eax, (%esp) ! movl %edx, 4(%esp) ! fldl (%esp) faddl 16(%esp) fstpl (%esp) ? movl 4(%esp), %edx addl $12, %esp ? movl %edx, %eax andl $-2147483648, %eax ret Instructions marked with (!) could be replaced with a fld1. Instructions marked with (?) could be replaced with a "movl 4(%esp), %eax". Perhaps fxam could be used in this case? Then the code would look something like: fldl 4(%esp) fxam fnstsw %ax fstp %st(0) andl 0x02, %eax ret
Confirmed.
It looks that REG_EQUAL notes gets lost between regmove and lreg pass. A relevant part from compiling an example in description with '-O2' shows: pr21508.c.19.regmove: (note:HI 7 6 12 0 NOTE_INSN_FUNCTION_BEG) (insn:HI 12 7 13 0 (set (reg:DF 62) (mem/u/i:DF (symbol_ref/u:SI ("*.LC1") [flags 0x2]) [2 S8 A64])) 65 {*movdf_nointeger} (nil) (expr_list:REG_EQUAL (const_double:DF -2147483648 [0x80000000] 1.0e+0 [0x0.8p+1]) (nil))) in pr21508.c.22.lreg: (note:HI 7 6 12 0 NOTE_INSN_FUNCTION_BEG) (insn:HI 12 7 13 0 (set (reg:DF 62) (mem/u/i:DF (symbol_ref/u:SI ("*.LC1") [flags 0x2]) [2 S8 A64])) 65 {*movdf_nointeger} (nil) (nil)) However, compiling a simple program, such as: double test (double a) { return a + 1.0; } results in fld1 insn being used. REG_EQUAL notes are still present in lreg dump file: (note:HI 7 6 11 0 NOTE_INSN_FUNCTION_BEG) (insn:HI 11 7 12 0 (set (reg:DF 61) (mem/u/i:DF (symbol_ref/u:SI ("*.LC1") [flags 0x2]) [2 S8 A64])) 65 {*movdf_nointeger} (nil) (expr_list:REG_EQUAL (const_double:DF -2147483648 [0x80000000] 1.0e+0 [0x0.8p+1]) (nil)))
On the mainline we get: subl $12, %esp fld1 faddl 16(%esp) fstpl (%esp) movl 4(%esp), %eax addl $12, %esp andl $-2147483648, %eax ret Which is optimial as there is no extra movl and there is fld1.