This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] RHS INDIRECT_REF optimizations (PR tree-optimization/26069)
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Jakub Jelinek" <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 12 Jan 2008 12:40:00 +0100
- Subject: Re: [PATCH] RHS INDIRECT_REF optimizations (PR tree-optimization/26069)
- References: <20080111193338.GU15450@devserv.devel.redhat.com>
On Jan 11, 2008 8:33 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> unsigned short x;
> ...
> y = *(short *) &x;
>
> can be optimized as
>
> y = (short) x;
>
> Similarly
> unsigned long x;
> ...
> y = *(char *) &x;
>
> can be optimized as
>
> y = (char) x; on little endian and
> y = (char) (x >> N); on big endian.
>
> It is especially helpful if the var is no longer addressable
> because of these transformations, but they work only on RHS,
> so they can't be done in fold_indirect_ref_1.
> With older GCCs this was usually optimized using ADDRESSOF,
> so this is actually a regression from 3.4.
I agree with Andrews remarks in general. Note that apart from the case
using (char *) the code invokes undefined behavior as it violates
aliasing rules.
Technically I think we should use common machinery via
folding VIEW_CONVERT_EXPRs for this kind of type-punning and
not sticking the simplification in indirect-ref folding (that is, in
indirect-ref folding build_fold a VIEW_CONVERT_EXPR).
So - to address the regression, can you restrict the optimization
to punning to char for now and stick the transformation itself
to folding of VIEW_CONVERT_EXPR? The renaming and
splitting of fold_indirect_ref_rhs looks ok.
I will address the missed optimization in forwprop during the
next stage1.
Thanks,
Richard.