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: Convert (type *)&A into &A->field_of_type_and_offset_0.


> On 4/6/07, Jan Hubicka <jh@suse.cz> wrote:
> >Hi,
> >this patch teach fold_unary to convert (type *)&A into
> >&A->field_of_type_and_offset_0. These constructs are common in C++ 
> >inheritance
> >and the strange cast is a stopper for various further optimizations.
> >The transformation matches couple hounderd times compiling Gerald's 
> >testcase,
> >but also on GCC bootstrap (in parser, genattrtab and other places)
> >Bootstrapped/regtested i686-linux, OK?
> 
> I think tree-ssa-ccp.c:maybe_fold_offset_to_component_ref has
> some "interesting" side-cases and does not require memory allocation
> but passes back component_refs, that looks better in my view.

Hmm, maybe_fold_offset_to_component_ref should've probably matched the
case I was looking into, but it didn't because it tries to recurse only
on the first field overlapping with offset specified, so on union and
offset of 0, it will goto found at first field of sufficient size and
won't look into rest of union. At least if I am reading the code right.

I however think the packing of COMPONENT_REFs there is quite poor: if we
don't have match, we can produce quite few dead COMPONENT_REFs since we
tend to fold each statement many times and if we produce a testcase with
many "bad guys" producing deep nest that don't result in transformation,
we would end up consuming a lot of memory. My implementation was done in
that way to do malloc/free pair IFF the transformation suceeds, that
should be cheaper overall.

I would probably duplicate "found" code into the loop so the loop can be
continued when match is not found on first union member. 

To avoid allocation, we can either have the list of refs like I do in my
code that might be dificult because various refs are needed, or we can
simply search twice - once without building the containers and if match
is found, second time doing the job...

Honza
> 
> Richard.


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