public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3064] Improve return slot handling in ipa-modref Date: Mon, 23 Aug 2021 07:22:29 +0000 (GMT) [thread overview] Message-ID: <20210823072229.F0E5B3858417@sourceware.org> (raw) https://gcc.gnu.org/g:59f38935d189027f172b4813a6056addaceb7cd3 commit r12-3064-g59f38935d189027f172b4813a6056addaceb7cd3 Author: Jan Hubicka <hubicka@ucw.cz> Date: Mon Aug 23 09:21:36 2021 +0200 Improve return slot handling in ipa-modref gcc/ChangeLog: * ipa-modref.c (analyze_ssa_name_flags): Improve handling of return slot. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/modref-1.C: New test. Diff: --- gcc/ipa-modref.c | 23 ++++++++++------------- gcc/testsuite/g++.dg/tree-ssa/modref-1.C | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 549153865b8..cb0a314cbeb 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -1709,19 +1709,8 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth, if (gimple_call_fn (use_stmt) == name) lattice[index].merge (~EAF_NOCLOBBER); - /* Return slot optimization would require bit of propagation; - give up for now. */ - if (gimple_call_return_slot_opt_p (call) - && gimple_call_lhs (call) != NULL_TREE - && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call)))) - { - if (dump_file) - fprintf (dump_file, "%*s Unhandled return slot opt\n", - depth * 4, ""); - lattice[index].merge (0); - } /* Recursion would require bit of propagation; give up for now. */ - else if (callee && !ipa && recursive_call_p (current_function_decl, + if (callee && !ipa && recursive_call_p (current_function_decl, callee)) lattice[index].merge (0); else @@ -1735,7 +1724,15 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth, /* Handle *name = func (...). */ if (gimple_call_lhs (call) && memory_access_to (gimple_call_lhs (call), name)) - lattice[index].merge_direct_store (); + { + lattice[index].merge_direct_store (); + /* Return slot optimization passes address of + LHS to callee via hidden parameter and this + may make LHS to escape. See PR 98499. */ + if (gimple_call_return_slot_opt_p (call) + && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call)))) + lattice[index].merge (EAF_NOREAD | EAF_DIRECT); + } /* We do not track accesses to the static chain (we could) so give up. */ diff --git a/gcc/testsuite/g++.dg/tree-ssa/modref-1.C b/gcc/testsuite/g++.dg/tree-ssa/modref-1.C new file mode 100644 index 00000000000..c742dfe8b33 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/modref-1.C @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +struct S { int a; char b[20]; S(); S(S const&); }; +volatile int global; + +__attribute__ ((noinline,noclone)) +struct S noescape (int *b) +{ + struct S a; + a.a = b!=0; + global = 1; + return a; +} + +void escape (struct S *p); + +__attribute__ ((noinline,noclone)) +int +test(int *b) +{ + struct S s = noescape (b); + escape (&s); + return *b; +} +int test2() +{ + int b=1234; + test (&b); + return b; +} +// ipa-modref should analyze parameter B of test as noescape. +// { dg-final { scan-tree-dump "return 1234" } }
reply other threads:[~2021-08-23 7:22 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=20210823072229.F0E5B3858417@sourceware.org \ --to=hubicka@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).