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] Improve RTL expansion of x+x and x*x


The following patch improves for intial RTL we generate for addition
and multiplication with identical operands.  This not only avoids
the duplicated RTL that must be identified and removed by CSE/life,
but often the RTL optimizers are unable to determine that these values
are identical once they've been expanded from tree form.

[It's also much cleaner to do this at RTL expansion in expr than
have fold introduce SAVE_EXPRs to record the equivalence. Yuch!]


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

Ok for mainline?


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

	* expr.c (expand_expr <PLUS_EXPR>): If operand_equal_p considers
	both operands of the addition equal, reuse the expanded RTL.
	(expand_expr <MULT_EXPR>): Likewise for multiplication.


Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.550
diff -c -3 -p -r1.550 expr.c
*** expr.c	14 Jun 2003 00:23:24 -0000	1.550
--- expr.c	14 Jun 2003 17:38:02 -0000
*************** expand_expr (exp, target, tmode, modifie
*** 8226,8232 ****
  	  || mode != ptr_mode)
  	{
  	  op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
! 	  op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
  	  if (op0 == const0_rtx)
  	    return op1;
  	  if (op1 == const0_rtx)
--- 8226,8236 ----
  	  || mode != ptr_mode)
  	{
  	  op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
! 	  if (! operand_equal_p (TREE_OPERAND (exp, 0),
! 				 TREE_OPERAND (exp, 1), 0))
! 	    op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
! 	  else
! 	    op1 = op0;
  	  if (op0 == const0_rtx)
  	    return op1;
  	  if (op1 == const0_rtx)
*************** expand_expr (exp, target, tmode, modifie
*** 8235,8241 ****
  	}

        op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, modifier);
!       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, modifier);

        /* We come here from MINUS_EXPR when the second operand is a
           constant.  */
--- 8239,8250 ----
  	}

        op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, modifier);
!       if (! operand_equal_p (TREE_OPERAND (exp, 0),
! 			     TREE_OPERAND (exp, 1), 0))
! 	op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
! 			   VOIDmode, modifier);
!       else
! 	op1 = op0;

        /* We come here from MINUS_EXPR when the second operand is a
           constant.  */
*************** expand_expr (exp, target, tmode, modifie
*** 8457,8463 ****
  	    }
  	}
        op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
!       op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
        return expand_mult (mode, op0, op1, target, unsignedp);

      case TRUNC_DIV_EXPR:
--- 8466,8476 ----
  	    }
  	}
        op0 = expand_expr (TREE_OPERAND (exp, 0), subtarget, VOIDmode, 0);
!       if (! operand_equal_p (TREE_OPERAND (exp, 0),
! 			     TREE_OPERAND (exp, 1), 0))
! 	op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX, VOIDmode, 0);
!       else
! 	op1 = op0;
        return expand_mult (mode, op0, op1, target, unsignedp);

      case TRUNC_DIV_EXPR:

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]