[PATCH] Fix canonicalization of addresses

Eric Botcazou ebotcazou@adacore.com
Wed Jan 7 07:12:00 GMT 2009


> Indeed.  But we canonicalize u - 2 to u + -2u.  So how about the following
> (untested apart from on the testcase)?
>
> Index: fold-const.c
> ===================================================================
> --- fold-const.c	(revision 143138)
> +++ fold-const.c	(working copy)
> @@ -7439,7 +7439,17 @@ fold_plusminus_mult_expr (enum tree_code
>    else if (TREE_CODE (arg1) == INTEGER_CST)
>      {
>        arg10 = build_one_cst (type);
> -      arg11 = arg1;
> +      /* As we canonicalize A - 2 to A + -2 get rid of that sign for
> +         the purpose of this canonicalization.  */
> +      if (TREE_INT_CST_HIGH (arg1) == -1
> +	  && negate_expr_p (arg1)
> +	  && code == PLUS_EXPR)
> +	{
> +	  arg11 = negate_expr (arg1);
> +	  code = MINUS_EXPR;
> +	}
> +      else
> +	arg11 = arg1;
>      }
>    else
>      {

This should indeed be equivalent to the first part of the patch.

-- 
Eric Botcazou



More information about the Gcc-patches mailing list