public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Martin Jambor <jamborm@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-782] tree-sra: Avoid refreshing into const base decls (PR 100453) Date: Thu, 13 May 2021 21:27:01 +0000 (GMT) [thread overview] Message-ID: <20210513212701.AE06C385800A@sourceware.org> (raw) https://gcc.gnu.org/g:ca9bb74a5f856ccdceb4797f18b0a4ac8f49d069 commit r12-782-gca9bb74a5f856ccdceb4797f18b0a4ac8f49d069 Author: Martin Jambor <mjambor@suse.cz> Date: Thu May 13 23:26:32 2021 +0200 tree-sra: Avoid refreshing into const base decls (PR 100453) When SRA transforms an assignment where the RHS is an aggregate decl that it creates replacements for, the (least efficient) fallback method of dealing with them is to store all the replacements back into the original decl and then let the original assignment takes itc sourse. That of course should not need to be done for TREE_READONLY bases which cannot change contents. The SRA code handled this situation in one of two necessary places but only for DECL_IN_CONSTANT_POOL const decls, this patch modifies both to check TREE_READONLY. gcc/ChangeLog: 2021-05-12 Martin Jambor <mjambor@suse.cz> PR tree-optimization/100453 * tree-sra.c (sra_modify_assign): All const base accesses do not need refreshing, not just those from decl_pool. (sra_modify_assign): Do not refresh into a const base decl. gcc/testsuite/ChangeLog: 2021-05-12 Martin Jambor <mjambor@suse.cz> PR tree-optimization/100453 * gcc.dg/tree-ssa/pr100453.c: New test. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/pr100453.c | 18 ++++++++++++++++++ gcc/tree-sra.c | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr100453.c b/gcc/testsuite/gcc.dg/tree-ssa/pr100453.c new file mode 100644 index 00000000000..0cf0ad23815 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr100453.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-options "-O1" } */ + +struct a { + int b : 4; +} d; +static int c, e; +static const struct a f; +static void g(const struct a h) { + for (; c < 1; c++) + d = h; + e = h.b; + c = h.b; +} +int main() { + g(f); + return 0; +} diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index 8dfc923ed7e..186cd62b476 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -4244,7 +4244,7 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator *gsi) || stmt_ends_bb_p (stmt)) { /* No need to copy into a constant-pool, it comes pre-initialized. */ - if (access_has_children_p (racc) && !constant_decl_p (racc->base)) + if (access_has_children_p (racc) && !TREE_READONLY (racc->base)) generate_subtree_copies (racc->first_child, rhs, racc->offset, 0, 0, gsi, false, false, loc); if (access_has_children_p (lacc)) @@ -4333,7 +4333,7 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator *gsi) } /* Restore the aggregate RHS from its components so the prevailing aggregate copy does the right thing. */ - if (access_has_children_p (racc)) + if (access_has_children_p (racc) && !TREE_READONLY (racc->base)) generate_subtree_copies (racc->first_child, rhs, racc->offset, 0, 0, gsi, false, false, loc); /* Re-load the components of the aggregate copy destination.
reply other threads:[~2021-05-13 21:27 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210513212701.AE06C385800A@sourceware.org \ --to=jamborm@gcc.gnu.org \ --cc=gcc-cvs@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).