This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] improve C++ code by changing fold-const.c
- From: Roger Sayle <roger at eyesopen dot com>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: Mark Mitchell <mark at codesourcery dot com>, <law at redhat dot com>, <gcc-patches at gcc dot gnu dot org>, Richard Henderson <rth at redhat dot com>
- Date: Thu, 27 May 2004 09:39:10 -0600 (MDT)
- Subject: 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.
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.