This is the mail archive of the 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] improve C++ code by changing fold-const.c

On Wed, 26 May 2004, Andrew Pinski wrote:
> Okay, I am going to look at a different way.

Hi Andrew,

I'm sorry that I've not found much time to help you with this.
However all six of your proposed patches are variations on folding
NOP_EXPR (t1, ADDR_EXPR (t2, ...)) into ADDR_EXPR (t1, ...).  As
you know fold already handles the case where t1 == t2, so I suspect
a better place to tackle this problem is elsewhere.

The pointer types (const int*), (int&) and (int*) really are all
distinct types, that need to be preserved by the middle-end.  The
thing that makes them all equivalent is that dereferencing them
all returns the same type, "int" [not that we can fool the "fold"
int believing they're really all the same].

I suspect that the optimization that you're trying to perform shouldn't
be in the NOP_EXPR part of fold, but in the INDIRECT_REF or COMPONENT_REF
sections of fold.

i.e.  INDIRECT_REF (NOP_EXPR (ADDR_EXPR (X))) => X much like we might
(should?) currently handle INDIRECT_REF (ADDR_EXPR (X)) => X.  Or even
more generally, INDIRECT_REF (NOP_EXPR (Y)) => INDIRECT_REF (Y) if the
types are compatible, as investigated/explored by your patch variations.

I apologise that I haven't had a chance to investigate this suggestion
further myself, but you can see how both the above transformations
generalize the problem you're trying to tackle but without messing with
the semantics of ADDR_EXPR.  Of course, implementing such "deep" folding
may require the tree-combiner functionality that has been proposed.


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