This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] RHS INDIRECT_REF optimizations (PR tree-optimization/26069)


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]