This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Reflexive expand_binop optimization


The following patch to optabs.c is another step towards improving
the code GCC produces for Scott Ladd's madelbrot benchmark.  Given
code of the form "z * z", the middle-end ends up calling expand_binop
with identical operands.  At optimization level -O2 and higher, the
flag_force_mem option requires the operands to be loaded from memory
into pseudos.  Unfortunately, the current code will load the same
memory location into two different pseudos.

This is not generally a problem because CSE and alias analysis will
eventually clean-up this duplication (almost always), but detecting
this case earlier generates fewer instructions, emits less RTL and
many other good things.  For example, it'll enable expand_binop to
special case squaring of complex numbers in a follow-up patch (because
the pseudos holding real/imaginary parts can now be tested for equality).


The following patch has been bootstrapped on i686-pc-linux-gnu, all
languages except treelang, and regression checked with a top-level
"make -k check" with no new failures.

Ok for mainline?


2003-06-01  Roger Sayle  <roger@eyesopen.com>

	* optabs.c (expand_binop): Attempt to reuse pseudos for duplicate
	non-volatile operands of binary operations.
	(prepare_cmp_insn): Likewise.


Index: optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.172
diff -c -3 -p -r1.172 optabs.c
*** optabs.c	15 Apr 2003 13:06:58 -0000	1.172
--- optabs.c	1 Jun 2003 01:19:08 -0000
*************** expand_binop (mode, binoptab, op0, op1,
*** 700,707 ****

    if (flag_force_mem)
      {
!       op0 = force_not_mem (op0);
!       op1 = force_not_mem (op1);
      }

    /* If subtracting an integer constant, convert this into an addition of
--- 700,716 ----

    if (flag_force_mem)
      {
!       /* Load duplicate non-volatile operands once.  */
!       if (rtx_equal_p (op0, op1) && ! volatile_refs_p (op0))
! 	{
! 	  op0 = force_not_mem (op0);
! 	  op1 = op0;
! 	}
!       else
! 	{
! 	  op0 = force_not_mem (op0);
! 	  op1 = force_not_mem (op1);
! 	}
      }

    /* If subtracting an integer constant, convert this into an addition of
*************** prepare_cmp_insn (px, py, pcomparison, s
*** 3571,3578 ****

    if (mode != BLKmode && flag_force_mem)
      {
!       x = force_not_mem (x);
!       y = force_not_mem (y);
      }

    /* If we are inside an appropriately-short loop and one operand is an
--- 3580,3596 ----

    if (mode != BLKmode && flag_force_mem)
      {
!       /* Load duplicate non-volatile operands once.  */
!       if (rtx_equal_p (x, y) && ! volatile_refs_p (x))
! 	{
! 	  x = force_not_mem (x);
! 	  y = x;
! 	}
!       else
! 	{
! 	  x = force_not_mem (x);
! 	  y = force_not_mem (y);
! 	}
      }

    /* If we are inside an appropriately-short loop and one operand is an


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]