Tr : [redundency elimination, code motion, commun expression elimination] GCC optimizations

Miles Bader miles@gnu.org
Tue Sep 27 07:18:00 GMT 2011


Jeff Law <law@redhat.com> writes:
> The tail merging code in the RTL optimizers might pick this stuff up
> and Tom's work on block merging might as well.  It'd be worth
> looking into why they aren't triggering.

Hmm, actually testing with a recent gcc snapshot, it _is_ merging the
two if-blocks:

   int a, b, c, d, e, f;
   extern void foo ();
   void t (int x)
   {
     if (x==1) { a=b; c=d; e=f; foo(); }
     if (x==2) { a=b; c=d; e=f; foo(); }
   }

=>

   t:
           cmpl	$1, %edi
           je	.L4
           cmpl	$2, %edi
           je	.L4
           rep
           ret
   .L4:
           movl	b(%rip), %eax
           movl	%eax, a(%rip)
           movl	d(%rip), %eax
           movl	%eax, c(%rip)
           movl	f(%rip), %eax
           movl	%eax, e(%rip)
           xorl	%eax, %eax
           jmp	foo
           ...
           .ident	"GCC: (Debian 20110924-1) 4.7.0 20110924 (experimental) [trunk revision 179143]"

-Miles

-- 
Quotation, n. The act of repeating erroneously the words of another. The words
erroneously repeated.



More information about the Gcc-help mailing list