]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR 81248] Fix ipa-sra size check
authorjamborm <jamborm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Nov 2017 10:33:06 +0000 (10:33 +0000)
committerjamborm <jamborm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Nov 2017 10:33:06 +0000 (10:33 +0000)
2017-11-27  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/81248
* tree-sra.c (splice_param_accesses): Remove size check.
(decide_one_param_reduction): Fix size check.
* gimple-pretty-print.c (dump_profile): Silence warning.
* params.def (PARAM_IPA_SRA_PTR_GROWTH_FACTOR): Adjust description.

testsuite/
* g++.dg/ipa/pr81248.C: New test.
* gcc.dg/tree-ssa/ssa-pre-31.c: Disable IPA-SRA.
* gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-2.c: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255163 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimple-pretty-print.c
gcc/params.def
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ipa/pr81248.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-2.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-31.c
gcc/tree-sra.c

index 75a860e3f814493e8776167327105bc63e70d9d0..cfb13935d1968bbdfa1ef794572a6e99570257ac 100644 (file)
@@ -1,3 +1,11 @@
+2017-11-27  Martin Jambor  <mjambor@suse.cz>
+
+       PR tree-optimization/81248
+       * tree-sra.c (splice_param_accesses): Remove size check.
+       (decide_one_param_reduction): Fix size check.
+       * gimple-pretty-print.c (dump_profile): Silence warning.
+       * params.def (PARAM_IPA_SRA_PTR_GROWTH_FACTOR): Adjust description.
+
 2017-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/81307
index 55c623e37bb4ab80d72147454f7ba30240fd1cfa..8bcc4e31bfbd967287f253d12e773b68dbff3270 100644 (file)
@@ -84,7 +84,7 @@ debug_gimple_stmt (gimple *gs)
 static const char *
 dump_profile (profile_count &count)
 {
-  char *buf;
+  char *buf = NULL;
   if (!count.initialized_p ())
     return "";
   if (count.ipa_p ())
index 89915d4fc7fcde6bc36b016a920ff6258d88ae16..93bd2cf75fe5a30fc6f5e290eba3d086353743d4 100644 (file)
@@ -971,8 +971,8 @@ DEFPARAM (PARAM_MIN_NONDEBUG_INSN_UID,
 
 DEFPARAM (PARAM_IPA_SRA_PTR_GROWTH_FACTOR,
          "ipa-sra-ptr-growth-factor",
-         "Maximum allowed growth of size of new parameters ipa-sra replaces "
-         "a pointer to an aggregate with.",
+         "Maximum allowed growth of number and total size of new parameters "
+         "that ipa-sra replaces a pointer to an aggregate with.",
          2, 0, 0)
 
 DEFPARAM (PARAM_TM_MAX_AGGREGATE_SIZE,
index 1c0930619f36466424c22fa0579ba21bc7e6fc07..0b0bac7a4d7dfa460a6f8483b2d34e011ab8a62c 100644 (file)
@@ -1,3 +1,10 @@
+2017-11-27  Martin Jambor  <mjambor@suse.cz>
+
+       PR tree-optimization/81248
+       * g++.dg/ipa/pr81248.C: New test.
+       * gcc.dg/tree-ssa/ssa-pre-31.c: Disable IPA-SRA.
+       * gcc/testsuite/gcc.dg/ipa/ipcp-cstagg-2.c: Likewise.
+
 2017-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        * g++.dg/ubsan/null-8.C (bar): New function.
diff --git a/gcc/testsuite/g++.dg/ipa/pr81248.C b/gcc/testsuite/g++.dg/ipa/pr81248.C
new file mode 100644 (file)
index 0000000..d55d2e7
--- /dev/null
@@ -0,0 +1,40 @@
+//  { dg-do compile }
+// { dg-options "-O2 -std=c++17 -fdump-tree-eipa_sra" }
+
+
+#include <type_traits>
+
+typedef unsigned char __uint8_t;
+typedef __uint8_t uint8_t;
+
+
+struct A {
+    A() = default;
+    A(const A& o) = default;
+    A(const volatile A& o) : m1(o.m1) {}
+    uint8_t m1{0};
+};
+
+volatile uint8_t v;
+
+template<typename T>
+void f(const T& x) __attribute__((noinline));
+template<typename T>
+void f(const T& x) {
+    if constexpr(std::is_same<std::remove_cv_t<T>, A>::value) {
+        v = x.m1;
+    }
+    else {
+        v = x;
+    }
+}
+
+uint8_t n1;
+A n2;
+
+int main() {
+    f(n1);
+    f(n2);
+}
+
+// { dg-final { scan-tree-dump-times "Adjusting call" 2 "eipa_sra" } }
index f82014024d4c0bf1b337b24ec2f6dc5f447dafd2..c1b6f0f73a37393373e4ab8ebe1a620668e9e155 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -fdump-ipa-cp-details" } */
+/* { dg-options "-O3 -fdump-ipa-cp-details -fno-ipa-sra" } */
 
 typedef struct S
 {
index 0dface557bec41bd150accf81efe524e6287d17a..6a33b942ad558e88f1e28fe8b8df7388dae9c137 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-pre" } */
+/* { dg-options "-O2 -fdump-tree-pre -fno-ipa-sra" } */
 
 typedef struct {
     unsigned int key;
index db490b20c3ed1049380dd3a51555f0de17c3afa3..866cff0edb045b606556f7ba8c800f48b1fd85ea 100644 (file)
@@ -4453,7 +4453,7 @@ static struct access *
 splice_param_accesses (tree parm, bool *ro_grp)
 {
   int i, j, access_count, group_count;
-  int agg_size, total_size = 0;
+  int total_size = 0;
   struct access *access, *res, **prev_acc_ptr = &res;
   vec<access_p> *access_vec;
 
@@ -4520,13 +4520,6 @@ splice_param_accesses (tree parm, bool *ro_grp)
       i = j;
     }
 
-  if (POINTER_TYPE_P (TREE_TYPE (parm)))
-    agg_size = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))));
-  else
-    agg_size = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (parm)));
-  if (total_size >= agg_size)
-    return NULL;
-
   gcc_assert (group_count > 0);
   return res;
 }
@@ -4537,7 +4530,7 @@ splice_param_accesses (tree parm, bool *ro_grp)
 static int
 decide_one_param_reduction (struct access *repr)
 {
-  int total_size, cur_parm_size, agg_size, new_param_count, parm_size_limit;
+  HOST_WIDE_INT total_size, cur_parm_size;
   bool by_ref;
   tree parm;
 
@@ -4546,15 +4539,9 @@ decide_one_param_reduction (struct access *repr)
   gcc_assert (cur_parm_size > 0);
 
   if (POINTER_TYPE_P (TREE_TYPE (parm)))
-    {
-      by_ref = true;
-      agg_size = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))));
-    }
+    by_ref = true;
   else
-    {
-      by_ref = false;
-      agg_size = cur_parm_size;
-    }
+    by_ref = false;
 
   if (dump_file)
     {
@@ -4567,7 +4554,7 @@ decide_one_param_reduction (struct access *repr)
     }
 
   total_size = 0;
-  new_param_count = 0;
+  int new_param_count = 0;
 
   for (; repr; repr = repr->next_grp)
     {
@@ -4595,22 +4582,28 @@ decide_one_param_reduction (struct access *repr)
 
   gcc_assert (new_param_count > 0);
 
-  if (optimize_function_for_size_p (cfun))
-    parm_size_limit = cur_parm_size;
-  else
-    parm_size_limit = (PARAM_VALUE (PARAM_IPA_SRA_PTR_GROWTH_FACTOR)
-                       * cur_parm_size);
-
-  if (total_size < agg_size
-      && total_size <= parm_size_limit)
+  if (!by_ref)
     {
-      if (dump_file)
-       fprintf (dump_file, "    ....will be split into %i components\n",
-                new_param_count);
-      return new_param_count;
+      if (total_size >= cur_parm_size)
+       return 0;
     }
   else
-    return 0;
+    {
+      int parm_num_limit;
+      if (optimize_function_for_size_p (cfun))
+       parm_num_limit = 1;
+      else
+       parm_num_limit = PARAM_VALUE (PARAM_IPA_SRA_PTR_GROWTH_FACTOR);
+
+      if (new_param_count > parm_num_limit
+         || total_size > (parm_num_limit * cur_parm_size))
+       return 0;
+    }
+
+  if (dump_file)
+    fprintf (dump_file, "    ....will be split into %i components\n",
+            new_param_count);
+  return new_param_count;
 }
 
 /* The order of the following enums is important, we need to do extra work for