On 02/01/2017 09:03 AM, Richard Biener wrote:

Currently we copy CONSTRUCTORs we cp_fold even if no elements fold
(we throw the copy away then).  That's wasteful and we can easily
do the copying on-demand.  For simplicity the following resorts
to memcpy-ing the whole original vector on the first change
and only overwrites changed elements in the folding loop
(I suspect that's usually faster given initializer elements do
usually not fold(?)).

That removes another 35MB GC memory use from the PR12245 testcase.
(the biggest offender there is, non-surprisingly the C++ preprocessor
tokens with 130MB followed by 35MB for the CONSTRUCTOR and 40MB for
INTEGER_CSTs).

Bootstrap / regtest running on x86_64-unknown-linux-gnu.

Ok for trunk if that succeeds?

Thanks,
Richard.

2017-02-01  Richard Biener  <rguent...@suse.de>

        PR cp/14179
        cp/
        * cp-gimplify.c (cp_fold): When folding a CONSTRUCTOR copy
        it lazily on the first changed element only and copy it
        fully upfront, only storing changed elements.

Index: gcc/cp/cp-gimplify.c
===================================================================
--- gcc/cp/cp-gimplify.c        (revision 245094)
+++ gcc/cp/cp-gimplify.c        (working copy)
@@ -2361,12 +2361,9 @@ cp_fold (tree x)
        bool changed = false;
        vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (x);
        vec<constructor_elt, va_gc> *nelts = NULL;

+               if (! changed)
+                 {
+                   nelts = elts->copy ();
+                   changed = true;
+                 }

doesn't this make 'changed' a synonym for 'nelts != NULL'? (so you could ditch the former)

nathan

--
Nathan Sidwell

Reply via email to