http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51244
--- Comment #6 from Oleg Endo <oleg.e...@t-online.de> 2011-12-28 15:59:35 UTC --- (In reply to comment #3) > Created attachment 26191 [details] > Proposed patch to improve some of the issues. > > The attached patch removes the useless sequence and still allows the -1 > constant to be CSE-ed for such cases as the example function above. > > I haven't ran all tests on it yet, but CSiBE shows average code size reduction > of approx. -0.1% for -m4* with some code size increases in some files. Some of the code size increases are caused by the ifcvt.c pass which tries to transform sequences like: int test_func_6 (int a, int b, int c) { if (a == 16) c = 0; return b + c; } into branch-free code like: mov r4,r0 ! 45 movsi_ie/2 [length = 2] cmp/eq #16,r0 ! 9 cmpeqsi_t/2 [length = 2] mov #-1,r0 ! 34 movsi_ie/3 [length = 2] negc r0,r0 ! 38 *negc [length = 2] neg r0,r0 ! 36 negsi2 [length = 2] and r6,r0 ! 37 *andsi3_compact/2 [length = 2] rts ! 48 *return_i [length = 2] add r5,r0 ! 14 *addsi3_compact [length = 2] instead of the more compact (and on SH4 most likely better): mov r4,r0 ! 41 movsi_ie/2 [length = 2] cmp/eq #16,r0 ! 9 cmpeqsi_t/2 [length = 2] bf 0f ! 34 *movsicc_t_true/2 [length = 4] mov #0,r6 0: add r5,r6 ! 14 *addsi3_compact [length = 2] rts ! 44 *return_i [length = 2] mov r6,r0 ! 19 movsi_ie/2 [length = 2] This particular case is handled in noce_try_store_flag_mask, which does the transformation if BRANCH_COST >= 2, which is true for -m4. I guess before the patch ifcvt didn't realize that this transformation can be applied. I've tried setting BRANCH_COST to 1, which avoids this transformation but increases overall code size a bit.