This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][C++] Save memory/time when folding CONSTRUCTORs
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Biener <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org, jason at redhat dot com
- Date: Wed, 1 Feb 2017 15:53:31 +0100
- Subject: Re: [PATCH][C++] Save memory/time when folding CONSTRUCTORs
- Authentication-results: sourceware.org; auth=none
- References: <alpine.LSU.2.20.1702011456580.12993@r111.fhfr.qr> <20170201141833.GD14051@tucnak> <alpine.LSU.2.20.1702011532290.12993@r111.fhfr.qr>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Feb 01, 2017 at 03:35:49PM +0100, Richard Biener wrote:
> > > changed = false;
> > > break;
> > > }
> > > - changed = true;
> > > + if (! changed)
> > > + {
> > > + nelts = elts->copy ();
> >
> > Isn't the above part unnecessarily expensive, e.g. for the case
> > where you have huge CONSTRUCTOR and recursive cp_fold changes already
> > the very first value? Wouldn't it be better to just do:
> > vec_safe_reserve (nelts, vec_safe_length (elts));
> > vec_quick_grow (nelts, i);
> > memcpy (nelts->address (), elts->address (),
> > i * sizeof (constructor_elt));
> > and then:
>
> It really depends on how many constructor elements usually fold.
> If every next element will fold then yes, otherwise a memcpy
> is going to be faster than individual vec_quick_push ()s with
> cache-trashing cp_fold calls inbetween.
>
> But I didn't benchmark anything, I just looked at memory use
> (for the case where nothing folds). And elts->copy () looks
> much "cleaner" than this reserve/grow/memcpy ;)
Maybe. But then it would be better not to do:
+ constructor_elt e = { p->index, op };
+ (*nelts)[i] = e;
but just
(*nelts)[i].value = op;
because (*nelts)[i].index has been already copied and is the same,
so no need to override it again.
Jakub