This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFH] Folding of &a[-1]
- From: Paul Schlie <schlie at comcast dot net>
- To: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Wed, 16 Feb 2005 11:53:25 -0500
- Subject: Re: [RFH] Folding of &a[-1]
> In fact, it is c-common.c:2289 that does -4 -> (int *)-4
> conversion, but pointer_int_sum is already called with PLUS_EXPR.
> build_unary_op unconditionally expands &x[y] to x+y, regardless
> of the sign of y. Of course the standard says that they are equal.
> But is &x[-1] == x + (int *)4*(int *)-1 ? From this follows that
> we have no way to convert this back to &x[-1], as we loose the
> sign information by the (int *) cast.
>
> How do the loop optimizers handle this - negative offsets by relying
> on unsigned pointer wrap-around?
Possibly more correct:
&x[-1] == (int *)x + (int *)((size_t)4*(int)-1)
=>
&x[-1] == (int *)x - (int *)((size_t)4*(size_t)1)
Implying that in general:
(unsigned)((unsigned)x * (signed)y)
=>
-((unsigned)x * (unsigned)y)
not:
+((unsigned)x * (unsigned)(signed)y)