[PATCH] Fix canonicalization of addresses

Richard Guenther richard.guenther@gmail.com
Tue Jan 13 21:23:00 GMT 2009


On Tue, Jan 13, 2009 at 10:17 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> 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. :-(

IMHO it's "correct" that it is canonicalized the same as X * n + n.  IMHO people
shouldn't try to fix this kind of problems at the point of
canonicalization either ;)

Richard.



More information about the Gcc-patches mailing list