]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
struct: New directory with tests for struct-reorg optimizaion.
authorOlga Golovanevsky <olga@il.ibm.com>
Thu, 13 Dec 2007 13:47:22 +0000 (13:47 +0000)
committerOlga Golovanevsky <olga@gcc.gnu.org>
Thu, 13 Dec 2007 13:47:22 +0000 (13:47 +0000)
2007-11-26  Olga Golovanevsky  <olga@il.ibm.com>

* gcc.dg/struct: New directory with tests
for struct-reorg optimizaion.
* gcc.dg/struct/struct-reorg.exp: New script.
* gcc.dg/struct/wo_prof_array_through_pointer.c: New test.
* gcc.dg/struct/wo_prof_malloc_size_var.c: Likewise.
* gcc.dg/struct/wo_prof_mult_field_peeling.c: Likewise.
* gcc.dg/struct/wo_prof_escape_arg_to_local.c: Likewise.
* gcc.dg/struct/wo_prof_escape_return.c: Likewise.
* gcc.dg/struct/wo_prof_escape_str_init.c: Likewise.
* gcc.dg/struct/wo_prof_escape_substr_array.c: Likewise.
* gcc.dg/struct/wo_prof_escape_substr_pointer.c: Likewise.
* gcc.dg/struct/wo_prof_escape_substr_value.c: Likewise.
* gcc.dg/struct/wo_prof_global_array.c: Likewise.
* gcc.dg/struct/wo_prof_global_var.c: Likewise.
* gcc.dg/struct/wo_prof_local_array.c: Likewise.
* gcc.dg/struct/wo_prof_local_var.c: Likewise.
* gcc.dg/struct/wo_prof_two_strs.c: Likewise.
* gcc.dg/struct/wo_prof_single_str_global.c: Likewise.
* gcc.dg/struct/wo_prof_single_str_local.c: Likewise.
* gcc.dg/struct/wo_prof_single_str_pointer.c: Likewise.
* gcc.dg/struct/w_prof_two_strs.c: Likewise.
* gcc.dg/struct/w_prof_global_array.c: Likewise.
* gcc.dg/struct/w_prof_global_var.c: Likewise.
* gcc.dg/struct/w_prof_local_array.c: Likewise.
* gcc.dg/struct/w_prof_local_var.c: Likewise.
* gcc.dg/struct/w_prof_single_str_global.c: Likewise.
* gcc.dg/struct/w_ratio_cold_str.c: Likewise.

From-SVN: r130893

26 files changed:
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/struct/struct-reorg.exp [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_prof_global_array.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_prof_global_var.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_prof_local_array.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_prof_local_var.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_prof_single_str_global.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_prof_two_strs.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/w_ratio_cold_str.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_array_through_pointer.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_escape_return.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_escape_str_init.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_array.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_pointer.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_value.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_global_array.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_global_var.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_local_array.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_local_var.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_malloc_size_var.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_mult_field_peeling.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_single_str_global.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_single_str_local.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_single_str_pointer.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/struct/wo_prof_two_strs.c [new file with mode: 0644]

index d665f7dbcf7647be35daecb3534d1a077f7a7757..087a0c8c36fc4cb788d0ce5e8d4280be14efb2b7 100644 (file)
@@ -1,3 +1,33 @@
+2007-11-26  Olga Golovanevsky  <olga@il.ibm.com>
+
+       * gcc.dg/struct: New directory with tests 
+       for struct-reorg optimizaion.
+       * gcc.dg/struct/struct-reorg.exp: New script.
+       * gcc.dg/struct/wo_prof_array_through_pointer.c: New test.
+       * gcc.dg/struct/wo_prof_malloc_size_var.c: Likewise.
+       * gcc.dg/struct/wo_prof_mult_field_peeling.c: Likewise.
+       * gcc.dg/struct/wo_prof_escape_arg_to_local.c: Likewise.
+       * gcc.dg/struct/wo_prof_escape_return.c: Likewise.
+       * gcc.dg/struct/wo_prof_escape_str_init.c: Likewise.
+       * gcc.dg/struct/wo_prof_escape_substr_array.c: Likewise.
+       * gcc.dg/struct/wo_prof_escape_substr_pointer.c: Likewise.
+       * gcc.dg/struct/wo_prof_escape_substr_value.c: Likewise.
+       * gcc.dg/struct/wo_prof_global_array.c: Likewise.
+       * gcc.dg/struct/wo_prof_global_var.c: Likewise.
+       * gcc.dg/struct/wo_prof_local_array.c: Likewise.
+       * gcc.dg/struct/wo_prof_local_var.c: Likewise.
+       * gcc.dg/struct/wo_prof_two_strs.c: Likewise.
+       * gcc.dg/struct/wo_prof_single_str_global.c: Likewise.
+       * gcc.dg/struct/wo_prof_single_str_local.c: Likewise.
+       * gcc.dg/struct/wo_prof_single_str_pointer.c: Likewise.
+       * gcc.dg/struct/w_prof_two_strs.c: Likewise.
+       * gcc.dg/struct/w_prof_global_array.c: Likewise.
+       * gcc.dg/struct/w_prof_global_var.c: Likewise.
+       * gcc.dg/struct/w_prof_local_array.c: Likewise.
+       * gcc.dg/struct/w_prof_local_var.c: Likewise.
+       * gcc.dg/struct/w_prof_single_str_global.c: Likewise.
+       * gcc.dg/struct/w_ratio_cold_str.c: Likewise.
+
 2007-12-13  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/34427
diff --git a/gcc/testsuite/gcc.dg/struct/struct-reorg.exp b/gcc/testsuite/gcc.dg/struct/struct-reorg.exp
new file mode 100644 (file)
index 0000000..392d555
--- /dev/null
@@ -0,0 +1,74 @@
+#   Copyright (C) 2007 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+
+# Test the functionality of programs compiled with profile-directed structure
+# rearrangement using -fprofile-generate followed by -fprofile-use.
+
+load_lib gcc-dg.exp
+load_lib target-supports.exp
+
+set DEFAULT_CFLAGS "-O3 -fipa-struct-reorg -fdump-ipa-all -fwhole-program -combine -fipa-type-escape"
+
+# Initialize `dg'.
+dg-init
+
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/wo_prof_*.c]] "" $DEFAULT_CFLAGS
+
+dg-final
+
+# Some targets don't support tree profiling.
+if { ![check_profiling_available ""] } {
+    return
+}
+
+# The procedures in profopt.exp need these parameters.
+set tool gcc
+set prof_ext "gcda gcno"
+
+# Override the list defined in profopt.exp.
+set PROFOPT_OPTIONS [list {}]
+
+if $tracelevel then {
+    strace $tracelevel
+}
+
+# Load support procs.
+load_lib profopt.exp
+
+# These are globals used by profopt-execute.  The first is options
+# needed to generate profile data, the second is options to use the
+# profile data.
+set common "-O3 -fwhole-program -combine -fipa-type-escape"
+set profile_option [concat $common " -fprofile-generate"]
+set feedback_option [concat $common " -fprofile-use -fipa-struct-reorg -fdump-ipa-all"]
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/w_prof_*.c]] {
+    # If we're only testing specific files and this isn't one of them, skip it.
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    profopt-execute $src
+}
+
+set feedback_option [concat $feedback_option " --param struct-reorg-cold-struct-ratio=30"]
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/w_ratio_*.c]] {
+    # If we're only testing specific files and this isn't one of them, skip it.
+    if ![runtest_file_p $runtests $src] then {
+        continue
+    }
+    profopt-execute $src
+}
diff --git a/gcc/testsuite/gcc.dg/struct/w_prof_global_array.c b/gcc/testsuite/gcc.dg/struct/w_prof_global_array.c
new file mode 100644 (file)
index 0000000..cbfd0bc
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+str_t A[N];
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < N; i++)
+    {
+      A[i].a = 0;
+    }
+
+  for (i = 0; i < N; i++)
+    if (A[i].a != 0) 
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/w_prof_global_var.c b/gcc/testsuite/gcc.dg/struct/w_prof_global_var.c
new file mode 100644 (file)
index 0000000..5fa1ca5
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+str_t *p;
+
+int
+main ()
+{
+  int i, sum;
+
+  p = malloc (N * sizeof (str_t));
+  for (i = 0; i < N; i++)
+    p[i].a = p[i].b + 1;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != p[i].b + 1)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/w_prof_local_array.c b/gcc/testsuite/gcc.dg/struct/w_prof_local_array.c
new file mode 100644 (file)
index 0000000..6394d07
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+int
+main ()
+{
+  int i;
+  str_t A[N];
+
+  for (i = 0; i < N; i++)
+    {
+      A[i].a = 0;
+    }
+
+  for (i = 0; i < N; i++)
+    if (A[i].a != 0) 
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/w_prof_local_var.c b/gcc/testsuite/gcc.dg/struct/w_prof_local_var.c
new file mode 100644 (file)
index 0000000..91d580f
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+int
+main ()
+{
+  int i, sum;
+
+  str_t * p = malloc (N * sizeof (str_t));
+  for (i = 0; i < N; i++)
+    p[i].a = p[i].b + 1;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != p[i].b + 1)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/w_prof_single_str_global.c b/gcc/testsuite/gcc.dg/struct/w_prof_single_str_global.c
new file mode 100644 (file)
index 0000000..db9372e
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  int b;
+}str_t;
+
+#define N 3
+
+str_t str;
+
+int
+main ()
+{
+  int i;
+  int res = 1<<(1<<N);
+  str.a = 2;
+
+  for (i = 0; i < N; i++)
+      str.a = str.a * str.a;
+  
+  if (str.a != res)
+    abort ();
+
+  return str.a;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
+
diff --git a/gcc/testsuite/gcc.dg/struct/w_prof_two_strs.c b/gcc/testsuite/gcc.dg/struct/w_prof_two_strs.c
new file mode 100644 (file)
index 0000000..aca646a
--- /dev/null
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+
+typedef struct
+{
+  int a;
+  float b;
+}str_t1;
+
+typedef struct
+{
+  int c;
+  float d;
+}str_t2;
+
+#define N 1000
+
+str_t1 *p1;
+str_t2 *p2;
+int num;
+
+void
+foo (void)
+{
+  int i;
+
+  for (i=0; i < num; i++)
+    p2[i].c = 2;
+}
+
+int
+main ()
+{
+  int i, r;
+
+  r = rand ();
+  num = r > N ? N : num; 
+  p1 = malloc (num * sizeof (str_t1));
+  p2 = malloc (num * sizeof (str_t2));
+
+  if (p1 == NULL || p2 == NULL)
+    return 0;
+
+  for (i = 0; i < num; i++)
+    p1[i].a = 1;
+
+  foo ();
+
+  for (i = 0; i < num; i++)
+    if (p1[i].a != 1 || p2[i].c != 2)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 2" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
+
diff --git a/gcc/testsuite/gcc.dg/struct/w_ratio_cold_str.c b/gcc/testsuite/gcc.dg/struct/w_ratio_cold_str.c
new file mode 100644 (file)
index 0000000..19de595
--- /dev/null
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  int b;
+}str_t1;
+
+typedef struct
+{
+  float a;
+  float b;
+}str_t2;
+
+#define N1 1000
+#define N2 100
+str_t1 A1[N1];
+str_t2 A2[N2];
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < N1; i++)
+    A1[i].a = 0;
+
+  for (i = 0; i < N2; i++)
+    A2[i].a = 0;
+
+  for (i = 0; i < N1; i++)
+    if (A1[i].a != 0) 
+      abort ();
+
+  for (i = 0; i < N2; i++)
+    if (A2[i].a != 0) 
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final-use { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final-use { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_array_through_pointer.c b/gcc/testsuite/gcc.dg/struct/wo_prof_array_through_pointer.c
new file mode 100644 (file)
index 0000000..0746019
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+int
+main ()
+{
+  int i;
+  str_t A[N];
+  str_t *p = A;
+
+  for (i = 0; i < N; i++)
+    p[i].a = 0;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != 0)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Currently str_t escapes due to incorrect ipa-type-escape analysis.  */
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" { xfail *-*-* } } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_arg_to_local.c
new file mode 100644 (file)
index 0000000..b120a79
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-options "-O3 -fno-inline -fipa-type-escape -fdump-ipa-all -fipa-struct-reorg -fwhole-program -combine" } */
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+struct str
+{
+  int a;
+  float b;
+};
+
+#define N 1000
+
+int
+foo (struct str * p_str)
+{
+  static int sum = 0;
+
+  sum = sum + p_str->a;
+  return sum;
+}
+
+int
+main ()
+{
+  int i, sum;
+  struct str * p = malloc (N * sizeof (struct str));
+
+  for (i = 0; i < N; i++)
+    sum = foo (p+i);
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "is passed to local function...Excluded." "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_return.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_return.c
new file mode 100644 (file)
index 0000000..26944fe
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-options "-O3 -fno-inline -fipa-type-escape -fdump-ipa-all -fipa-struct-reorg -fwhole-program -combine" } */
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+
+struct A {
+  int d;
+};
+
+struct A a;
+
+struct A foo ()
+{
+  a.d = 5;
+  return a;
+}
+
+int
+main ()
+{
+  a.d = 0;
+  foo ();
+
+  if (a.d != 5)
+    abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "is return type of function...Excluded" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_str_init.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_str_init.c
new file mode 100644 (file)
index 0000000..5f634fc
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  int b;
+}str_t;
+
+#define N 2
+
+str_t A[2] = {{1,1},{2,2}};
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < N; i++)
+    A[i].b = A[i].a;
+
+  for (i = 0; i < N; i++)
+    if (A[i].b != A[i].a)
+      abort ();
+  
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "is initialized...Excluded" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
+
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_array.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_array.c
new file mode 100644 (file)
index 0000000..55a644e
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+typedef struct 
+{
+  str_t A[N];
+  int c;
+}str_with_substr_t;
+
+str_with_substr_t a;
+
+int
+main ()
+{
+  int i;
+  
+  for (i = 0; i < N; i++)
+    a.A[i].b = 0;
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "is a field in the structure" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_pointer.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_pointer.c
new file mode 100644 (file)
index 0000000..fcb10e3
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+typedef struct 
+{
+  str_t * sub_str;
+  int c;
+}str_with_substr_t;
+
+int
+main (void)
+{
+  int i;
+  str_with_substr_t A[N];
+  str_t a[N];
+
+  for (i=0; i < N; i++)
+    A[i].sub_str = &(a[i]);
+
+  for (i=0; i < N; i++)
+    A[i].sub_str->a = 5;
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "is a field in the structure" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_value.c b/gcc/testsuite/gcc.dg/struct/wo_prof_escape_substr_value.c
new file mode 100644 (file)
index 0000000..49283a5
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+typedef struct 
+{
+  str_t sub_str;
+  int c;
+}str_with_substr_t;
+
+int
+main ()
+{
+  int i;
+  str_with_substr_t A[N];
+
+  for (i = 0; i < N; i++)
+    A[i].sub_str.a = 5;
+
+  for (i = 0; i < N; i++)
+    if (A[i].sub_str.a != 5)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "is a field in the structure" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_global_array.c b/gcc/testsuite/gcc.dg/struct/wo_prof_global_array.c
new file mode 100644 (file)
index 0000000..1254281
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+str_t A[N];
+
+int
+main ()
+{
+  int i;
+
+  for (i = 0; i < N; i++)
+    {
+      A[i].a = 0;
+    }
+
+  for (i = 0; i < N; i++)
+    if (A[i].a != 0) 
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_global_var.c b/gcc/testsuite/gcc.dg/struct/wo_prof_global_var.c
new file mode 100644 (file)
index 0000000..7e08e96
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+str_t *p;
+
+int
+main ()
+{
+  int i, sum;
+
+  p = malloc (N * sizeof (str_t));
+  for (i = 0; i < N; i++)
+    p[i].a = p[i].b + 1;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != p[i].b + 1)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_local_array.c b/gcc/testsuite/gcc.dg/struct/wo_prof_local_array.c
new file mode 100644 (file)
index 0000000..28d66e4
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+int
+main ()
+{
+  int i;
+  str_t A[N];
+
+  for (i = 0; i < N; i++)
+    {
+      A[i].a = 0;
+    }
+
+  for (i = 0; i < N; i++)
+    if (A[i].a != 0) 
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_local_var.c b/gcc/testsuite/gcc.dg/struct/wo_prof_local_var.c
new file mode 100644 (file)
index 0000000..e931efa
--- /dev/null
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+int
+main ()
+{
+  int i, sum;
+
+  str_t * p = malloc (N * sizeof (str_t));
+  for (i = 0; i < N; i++)
+    p[i].a = p[i].b + 1;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != p[i].b + 1)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_malloc_size_var.c b/gcc/testsuite/gcc.dg/struct/wo_prof_malloc_size_var.c
new file mode 100644 (file)
index 0000000..b1614c0
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+}str_t;
+
+#define N 1000
+
+int
+main ()
+{
+  int i, num;
+
+  num = rand(); 
+  str_t * p = malloc (num * sizeof (str_t));
+
+  if (p == 0)
+    return 0;
+
+  for (i = 0; i < N; i++)
+    p[i].a = p[i].b + 1;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != p[i].b + 1)
+      abort ();
+  
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* Currently the condition `if (p == 0)` is incorrectly reported as unsafe.  */
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" { xfail *-*-* } } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_mult_field_peeling.c b/gcc/testsuite/gcc.dg/struct/wo_prof_mult_field_peeling.c
new file mode 100644 (file)
index 0000000..df2b4ee
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  float b;
+  int c;
+  float d;
+}str_t;
+
+#define N 100
+
+int 
+main ()
+{
+  int i;
+  str_t *p = malloc (N * sizeof (str_t));
+
+  for (i = 0; i < N; i++)
+    p[i].a = 5;
+
+  for (i = 0; i < N; i++)
+    if (p[i].a != 5)      
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* The structure str_t is erroneously peeled into 4 structures instead of 2.  */
+/* { dg-final { scan-ipa-dump "the number of new types is 2" "ipa_struct_reorg" { xfail *-*-* } } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_single_str_global.c b/gcc/testsuite/gcc.dg/struct/wo_prof_single_str_global.c
new file mode 100644 (file)
index 0000000..5569deb
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  int b;
+}str_t;
+
+#define N 3
+
+str_t str;
+
+int
+main ()
+{
+  int i;
+  int res = 1<<(1<<N);
+  str.a = 2;
+
+  for (i = 0; i < N; i++)
+    str.a = str.a * str.a;
+  
+  if (str.a != res)
+    abort ();
+
+  return str.a;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_single_str_local.c b/gcc/testsuite/gcc.dg/struct/wo_prof_single_str_local.c
new file mode 100644 (file)
index 0000000..65a9602
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  int b;
+}str_t;
+
+#define N 3
+
+int
+main ()
+{
+  int i;
+  int res = 1<<(1<<N);
+  str_t str;
+  
+  str.a = 2;
+
+  for (i = 0; i < N; i++)
+    str.a = str.a * str.a;
+  
+  if (str.a != res)
+    abort ();
+
+  return str.a;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "No structures to transform" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_single_str_pointer.c b/gcc/testsuite/gcc.dg/struct/wo_prof_single_str_pointer.c
new file mode 100644 (file)
index 0000000..fd56257
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+typedef struct
+{
+  int a;
+  int *b;
+}str_t;
+
+#define N 3
+
+str_t *p;
+
+int
+main ()
+{
+  str_t str;
+  int i;
+  int res = 1 << (1 << N);
+  p = &str;
+  str.a = 2;
+  p->b = &(p->a);
+
+  for (i=0; i < N; i++)
+    p->a = *(p->b)*(*(p->b));
+
+  if (p->a != res)
+    abort ();
+  
+  return p->a;
+}
+
+/*--------------------------------------------------------------------------*/
+/* The access &(p->a) is handled incorrectly in ipa-struct-reorg.c.  */
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" { xfail *-*-* } } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */
diff --git a/gcc/testsuite/gcc.dg/struct/wo_prof_two_strs.c b/gcc/testsuite/gcc.dg/struct/wo_prof_two_strs.c
new file mode 100644 (file)
index 0000000..5fb152a
--- /dev/null
@@ -0,0 +1,60 @@
+/* { dg-do compile } */
+/* { dg-do run } */
+
+#include <stdlib.h>
+
+typedef struct
+{
+  int a;
+  float b;
+}str_t1;
+
+typedef struct
+{
+  int c;
+  float d;
+}str_t2;
+
+#define N 1000
+
+str_t1 *p1;
+str_t2 *p2;
+int num;
+
+void
+foo (void)
+{
+  int i;
+
+  for (i=0; i < num; i++)
+    p2[i].c = 2;
+}
+
+int
+main ()
+{
+  int i, r;
+
+  r = rand ();
+  num = r > N ? N : num; 
+  p1 = malloc (num * sizeof (str_t1));
+  p2 = malloc (num * sizeof (str_t2));
+
+  if (p1 == NULL || p2 == NULL)
+    return 0;
+
+  for (i = 0; i < num; i++)
+    p1[i].a = 1;
+
+  foo ();
+
+  for (i = 0; i < num; i++)
+    if (p1[i].a != 1 || p2[i].c != 2)
+      abort ();
+
+  return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+/* { dg-final { scan-ipa-dump "Number of structures to transform is 2" "ipa_struct_reorg" } } */
+/* { dg-final { cleanup-ipa-dump "*" } } */