diff options
author | Sergei Trofimovich <siarheit@google.com> | 2021-01-11 18:05:57 +0000 |
---|---|---|
committer | Sergei Trofimovich <siarheit@google.com> | 2021-02-01 18:13:42 +0000 |
commit | 11056ab7687f7156846e93557c9171b77713bd7e (patch) | |
tree | 5f6dd9686df74d079fbd0f61f6fb795a4e9d7122 /gcc | |
parent | 8bfdf51d8595537937f990947a7a36d3a63dca5f (diff) | |
download | gcc-11056ab7687f7156846e93557c9171b77713bd7e.zip gcc-11056ab7687f7156846e93557c9171b77713bd7e.tar.gz gcc-11056ab7687f7156846e93557c9171b77713bd7e.tar.bz2 |
tree-optimization/98499 - fix modref analysis on RVO statements
Before the change RVO gimple statements were treated as local
stores by modres analysis. But in practice RVO escapes target.
2021-02-01 Sergei Trofimovich <siarheit@google.com>
gcc/ChangeLog:
PR tree-optimization/98499
* ipa-modref.c (analyze_ssa_name_flags): treat RVO
conservatively and assume all possible side-effects.
gcc/testsuite/ChangeLog:
PR tree-optimization/98499
* g++.dg/pr98499.C: new test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ipa-modref.c | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/pr98499.C | 31 |
2 files changed, 45 insertions, 4 deletions
diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 8a5669c..7aaf53b 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -36,7 +36,7 @@ along with GCC; see the file COPYING3. If not see The following information is computed 1) load/store access tree described in ipa-modref-tree.h - This is used by tree-ssa-alias to disambiguate load/dtores + This is used by tree-ssa-alias to disambiguate load/stores 2) EAF flags used by points-to analysis (in tree-ssa-structlias). and defined in tree-core.h. and stored to optimization_summaries. @@ -1604,7 +1604,7 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth, continue; if (dump_file) { - fprintf (dump_file, "%*s Analyzing stmt:", depth * 4, ""); + fprintf (dump_file, "%*s Analyzing stmt: ", depth * 4, ""); print_gimple_stmt (dump_file, use_stmt, 0); } @@ -1621,9 +1621,19 @@ analyze_ssa_name_flags (tree name, vec<modref_lattice> &lattice, int depth, else if (gcall *call = dyn_cast <gcall *> (use_stmt)) { tree callee = gimple_call_fndecl (call); - + /* Return slot optiomization 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. */ - if (callee && !ipa && recursive_call_p (current_function_decl, + else if (callee && !ipa && recursive_call_p (current_function_decl, callee)) lattice[index].merge (0); else diff --git a/gcc/testsuite/g++.dg/pr98499.C b/gcc/testsuite/g++.dg/pr98499.C new file mode 100644 index 0000000..ace088a --- /dev/null +++ b/gcc/testsuite/g++.dg/pr98499.C @@ -0,0 +1,31 @@ +/* PR tree-optimization/98499. */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +struct string { + // pointer to local store + char * _M_buf; + // local store + char _M_local_buf[16]; + + __attribute__((noinline)) string() : _M_buf(_M_local_buf) {} + + ~string() { + if (_M_buf != _M_local_buf) + __builtin_trap(); + } + + string(const string &__str); // no copies +}; + +__attribute__((noinline)) static string dir_name() { return string(); } +class Importer { + string base_path; + +public: + __attribute__((noinline)) Importer() : base_path (dir_name()) {} +}; + +int main() { + Importer imp; +} |