public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96197] Excess memory consumption, positive correlation with the size of a constexpr array Date: Fri, 31 Jul 2020 02:29:49 +0000 [thread overview] Message-ID: <bug-96197-4-Gxr49Y8SkM@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-96197-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96197 --- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:8c00059ce058ea2aec2933319e270f5443b8b909 commit r11-2445-g8c00059ce058ea2aec2933319e270f5443b8b909 Author: Patrick Palka <ppalka@redhat.com> Date: Thu Jul 30 22:21:41 2020 -0400 c++: decl_constant_value and unsharing [PR96197] In the testcase from the PR we're seeing excessive memory use (> 5GB) during constexpr evaluation, almost all of which is due to the call to decl_constant_value in the VAR_DECL/CONST_DECL branch of cxx_eval_constant_expression. We reach here every time we evaluate an ARRAY_REF of a constexpr VAR_DECL, and from there decl_constant_value makes an unshared copy of the VAR_DECL's initializer. But unsharing here is unnecessary because callers of cxx_eval_constant_expression already unshare its result when necessary. To fix this excessive unsharing, this patch adds a new defaulted parameter unshare_p to decl_really_constant_value and decl_constant_value so that callers can control whether to unshare. As a simplification, we can also move the call to unshare_expr in constant_value_1 outside of the loop, since doing unshare_expr on a DECL_P is a no-op. Now that we no longer unshare the result of decl_constant_value and decl_really_constant_value from cxx_eval_constant_expression, memory use during constexpr evaluation for the testcase from the PR falls from ~5GB to 15MB according to -ftime-report. gcc/cp/ChangeLog: PR c++/96197 * constexpr.c (cxx_eval_constant_expression) <case CONST_DECL>: Pass false to decl_constant_value and decl_really_constant_value so that they don't unshare their result. * cp-tree.h (decl_constant_value): New declaration with an added bool parameter. (decl_really_constant_value): Add bool parameter defaulting to true to existing declaration. * init.c (constant_value_1): Add bool parameter which controls whether to unshare the initializer before returning. Call unshare_expr at most once. (scalar_constant_value): Pass true to constant_value_1's new bool parameter. (decl_really_constant_value): Add bool parameter and forward it to constant_value_1. (decl_constant_value): Likewise, but instead define a new overload with an added bool parameter. gcc/testsuite/ChangeLog: PR c++/96197 * g++.dg/cpp1y/constexpr-array8.C: New test.
next prev parent reply other threads:[~2020-07-31 2:29 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-14 15:30 [Bug c++/96197] New: " hyena at hyena dot net.ee 2020-07-15 6:29 ` [Bug c++/96197] " rguenth at gcc dot gnu.org 2020-07-15 8:47 ` hyena at hyena dot net.ee 2020-07-15 9:10 ` rguenther at suse dot de 2020-07-15 9:42 ` hyena at hyena dot net.ee 2020-07-21 16:17 ` ppalka at gcc dot gnu.org 2020-07-21 19:49 ` tridacnid at gmail dot com 2020-07-31 2:29 ` cvs-commit at gcc dot gnu.org [this message] 2020-07-31 13:51 ` ppalka at gcc dot gnu.org 2021-01-09 3:52 ` cvs-commit at gcc dot gnu.org 2021-01-09 3:54 ` ppalka at gcc dot gnu.org 2021-01-09 3:58 ` ppalka at gcc dot gnu.org 2021-01-18 15:39 ` ppalka at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-96197-4-Gxr49Y8SkM@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).