[PATCH] Fix canonicalization of addresses

Eric Botcazou ebotcazou@adacore.com
Tue Jan 13 21:18:00 GMT 2009


> 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
>      {

Note that this has also changed the canonicalization of X*n + (-n) with n not 
a power of 2.  Previously it was left untouched; now it's canonicalized into
(X + -1) * n, like its positive counterpart.  Which ends up having a visible 
detrimental effect for my own testcase at -O2. :-(

-- 
Eric Botcazou



More information about the Gcc-patches mailing list