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] Replace "goto both_summands" with simplify_gen_binary.


The following patch is a clean-up of expand_expr.  When I started,
it was only intended to be a one line tweak to replace

<       temp = simplify_binary_operation (PLUS, mode, op0, op1);
<       return temp ? temp : gen_rtx_PLUS (mode, op0, op1);

with the almost equivalent and preferred:

>	return simplify_gen_binary (PLUS, mode, op0, op1)


I then started noticing that the code immediately before this hunk
to swap operands to place integers last and multiplications first
was already handled in s_g_b.  Then I noticed that the code before that
that tried to accumulate integer constants, (X+C1)+C2 as X+(C1+C2)
and (X+C1)+(Y+C2) as (X+Y)+(C1+C2), was also already performed by
simplify_gen_binary.  And before I knew it, all 45 lines of code
after expand_expr's both_summands label could be replaced with a
single call to simplify_gen_binary.  Then the dominos kept falling
as I decided to clean-up the all the places that jumped to the
both_summands label with the equivalent call to simplify_gen_binary
which allowed the removal of the both_summands label itself.

Ah, the benefits of unifying our RTL simplifications...

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-09-02  Roger Sayle  <roger@eyesopen.com>

	* expr.c (expand_expr): The code following both_summands performs
	the same task as simplify_gen_binary.  Replace all gotos to
	both_summands with a call to simplify_gen_binary and delete the
	now unused label.


Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.580
diff -c -3 -p -r1.580 expr.c
*** expr.c	29 Aug 2003 22:25:19 -0000	1.580
--- expr.c	2 Sep 2003 01:47:03 -0000
*************** expand_expr (tree exp, rtx target, enum
*** 8110,8120 ****
  		{
  		  op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
  				     VOIDmode, modifier);
! 		  /* Don't go to both_summands if modifier
! 		     says it's not right to return a PLUS.  */
! 		  if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
! 		    goto binop2;
! 		  goto both_summands;
  		}
  	      /* Use immed_double_const to ensure that the constant is
  		 truncated according to the mode of OP1, then sign extended
--- 8110,8120 ----
  		{
  		  op1 = expand_expr (TREE_OPERAND (exp, 1), NULL_RTX,
  				     VOIDmode, modifier);
! 		  /* Return a PLUS if modifier says it's OK.  */
! 		  if (modifier == EXPAND_SUM
! 		      || modifier == EXPAND_INITIALIZER)
! 		    return simplify_gen_binary (PLUS, mode, op0, op1);
! 		  goto binop2;
  		}
  	      /* Use immed_double_const to ensure that the constant is
  		 truncated according to the mode of OP1, then sign extended
*************** expand_expr (tree exp, rtx target, enum
*** 8161,8215 ****
  			   VOIDmode, modifier);
        else
  	op1 = op0;
!
!       /* We come here from MINUS_EXPR when the second operand is a
!          constant.  */
!     both_summands:
!       /* Make sure any term that's a sum with a constant comes last.  */
!       if (GET_CODE (op0) == PLUS
! 	  && CONSTANT_P (XEXP (op0, 1)))
! 	{
! 	  temp = op0;
! 	  op0 = op1;
! 	  op1 = temp;
! 	}
!       /* If adding to a sum including a constant,
! 	 associate it to put the constant outside.  */
!       if (GET_CODE (op1) == PLUS
! 	  && CONSTANT_P (XEXP (op1, 1)))
! 	{
! 	  rtx constant_term = const0_rtx;
!
! 	  temp = simplify_binary_operation (PLUS, mode, XEXP (op1, 0), op0);
! 	  if (temp != 0)
! 	    op0 = temp;
! 	  /* Ensure that MULT comes first if there is one.  */
! 	  else if (GET_CODE (op0) == MULT)
! 	    op0 = gen_rtx_PLUS (mode, op0, XEXP (op1, 0));
! 	  else
! 	    op0 = gen_rtx_PLUS (mode, XEXP (op1, 0), op0);
!
! 	  /* Let's also eliminate constants from op0 if possible.  */
! 	  op0 = eliminate_constant_term (op0, &constant_term);
!
! 	  /* CONSTANT_TERM and XEXP (op1, 1) are known to be constant, so
! 	     their sum should be a constant.  Form it into OP1, since the
! 	     result we want will then be OP0 + OP1.  */
!
! 	  temp = simplify_binary_operation (PLUS, mode, constant_term,
! 					    XEXP (op1, 1));
! 	  if (temp != 0)
! 	    op1 = temp;
! 	  else
! 	    op1 = gen_rtx_PLUS (mode, constant_term, XEXP (op1, 1));
! 	}
!
!       /* Put a constant term last and put a multiplication first.  */
!       if (CONSTANT_P (op0) || GET_CODE (op1) == MULT)
! 	temp = op1, op1 = op0, op0 = temp;
!
!       temp = simplify_binary_operation (PLUS, mode, op0, op1);
!       return temp ? temp : gen_rtx_PLUS (mode, op0, op1);

      case MINUS_EXPR:
        /* For initializers, we are allowed to return a MINUS of two
--- 8161,8167 ----
  			   VOIDmode, modifier);
        else
  	op1 = op0;
!       return simplify_gen_binary (PLUS, mode, op0, op1);

      case MINUS_EXPR:
        /* For initializers, we are allowed to return a MINUS of two
*************** expand_expr (tree exp, rtx target, enum
*** 8256,8262 ****
        if (GET_CODE (op1) == CONST_INT)
  	{
  	  op1 = negate_rtx (mode, op1);
! 	  goto both_summands;
  	}

        goto binop2;
--- 8208,8214 ----
        if (GET_CODE (op1) == CONST_INT)
  	{
  	  op1 = negate_rtx (mode, op1);
! 	  return simplify_gen_binary (PLUS, mode, op0, op1);
  	}

        goto binop2;

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]