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: PR37363: PR36090 and PR36182 all over again


Paolo Bonzini <bonzini@gnu.org> writes:
> Index: cse.c
> ===================================================================
> --- cse.c	(revision 134435)
> +++ cse.c	(working copy)
> @@ -3161,10 +3161,8 @@ fold_rtx (rtx x, rtx insn)
>  	   FIXME: those ports should be fixed.  */
>  	if (new != 0 && is_const
>  	    && GET_CODE (new) == PLUS
> -	    && (GET_CODE (XEXP (new, 0)) == SYMBOL_REF
> -		|| GET_CODE (XEXP (new, 0)) == LABEL_REF)
>  	    && GET_CODE (XEXP (new, 1)) == CONST_INT)
> -	  new = gen_rtx_CONST (mode, new);
> +	  new = plus_constant (XEXP (new, 0), XEXP (new, 1));
> +	else
> +	  new = plus_constant (new, 0);
>        }
>        break;

I'm not sure about this bit.

First of all, isn't the whole of the original "if" statement
redundant these days?  "new" is the result of simplify_unary_operation,
and I'd have expected that function to return:

   (const (plus [symbol_ref|label_ref] (const_int X)))

rather than:

   (plus [symbol_ref|label_ref] (const_int X))

I think the same true of the revised "if" statement too: if plus_constant
could add a CONST, simplify_unary_operation should already have done that.

(The "else" bit isn't safe against "new" being NULL, btw.)

Couldn't:

      {
	int is_const = 0;

	/* We can't simplify extension ops unless we know the
	   original mode.  */
	if ((code == ZERO_EXTEND || code == SIGN_EXTEND)
	    && mode_arg0 == VOIDmode)
	  break;

	/* If we had a CONST, strip it off and put it back later if we
	   fold.  */
	if (const_arg0 != 0 && GET_CODE (const_arg0) == CONST)
	  is_const = 1, const_arg0 = XEXP (const_arg0, 0);

	new = simplify_unary_operation (code, mode,
					const_arg0 ? const_arg0 : folded_arg0,
					mode_arg0);
	/* NEG of PLUS could be converted into MINUS, but that causes
	   expressions of the form
	   (CONST (MINUS (CONST_INT) (SYMBOL_REF)))
	   which many ports mistakenly treat as LEGITIMATE_CONSTANT_P.
	   FIXME: those ports should be fixed.  */
	if (new != 0 && is_const
	    && GET_CODE (new) == PLUS
	    && (GET_CODE (XEXP (new, 0)) == SYMBOL_REF
		|| GET_CODE (XEXP (new, 0)) == LABEL_REF)
	    && GET_CODE (XEXP (new, 1)) == CONST_INT)
	  new = gen_rtx_CONST (mode, new);
      }

simply be replaced by:

      /* We can't simplify extension ops unless we know the
	 original mode.  */
      if ((code == ZERO_EXTEND || code == SIGN_EXTEND)
	  && mode_arg0 == VOIDmode)
	break;

      new = simplify_unary_operation (code, mode,
				      const_arg0 ? const_arg0 : folded_arg0,
				      mode_arg0);
?

(Sorry if I'm repeating earlier discussion here.)

Richard


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