This is the mail archive of the gcc@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]

Re: Does zero_extend (const_int) *ever* have a valid meaning


> On Fri, Sep 20, 2002 at 06:36:42PM +0100, Richard Earnshaw wrote:
> > So the next question is, should rtx_cost be required to accept this 
> > invalid RTL, or should we find a way to prevent the substitution into the 
> > original expression?
> 
> I wonder if we can compute the cost prior to simplification?

I was thinking just the same thing on the way home last night.

The answer appears to be yes.  The following patch fixes the problem:

Tested on i686-linux-gnu and arm-elf with no regressions.

However, I'm still a little uncomfortable that we allow an invalid change 
to creep in at a deep recursion of fold_rtx that we expect one of the 
callers to clean up correctly.

2002-09-21  Richard Earnshaw  (rearnsha@arm.com)

	PR opt/7930
	* cse.c (fold_rtx): Calculate old_cost before we fold each
	operand.


Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.235
diff -p -r1.235 cse.c
*** cse.c	20 Sep 2002 17:50:46 -0000	1.235
--- cse.c	21 Sep 2002 17:01:32 -0000
*************** fold_rtx (x, insn)
*** 3732,3737 ****
--- 3732,3738 ----
  	rtx cheap_arg, expensive_arg;
  	rtx replacements[2];
  	int j;
+ 	int old_cost = COST_IN (XEXP (x, i), code);
  
  	/* Most arguments are cheap, so handle them specially.  */
  	switch (GET_CODE (arg))
*************** fold_rtx (x, insn)
*** 3822,3828 ****
  
  	for (j = 0; j < 2 && replacements[j]; j++)
  	  {
- 	    int old_cost = COST_IN (XEXP (x, i), code);
  	    int new_cost = COST_IN (replacements[j], code);
  
  	    /* Stop if what existed before was cheaper.  Prefer constants
--- 3823,3828 ----

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