This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Disable -fipa-type-escape (PR tree-optimization/33136)


Hi!

may_alias_p uses ipa_type_escape_field_does_not_clobber_p wrongly
(apparently already since when ipa-type-escape.c was added back during 4.1
development), so it pretty much gives random answers whether something can
or can't alias.
When I have fixed that and also taught ipa-type-escape.c (analyze_function)
to consider phi nodes, I still haven't been able to construct a testcase
where it actually optimized what it is supposed to optimize, there
are several other bugs lurking int it
(see my http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33136#c28 WIP patch).

Therefore, I think it is best to just turn this pass off on 4.1/4.2 branches
and probably also on the trunk until it is really fixed and the pass does
there any good rather than just breaking valid code.

Vlad Makarov kindly ran SPEC2000 comparing -O2 base with -O2 -fno-ipa-type-escape
peak and there was no difference on SPECfp2000 and SPECint2000 even improved
by 0.54%, so I don't think there is much harm to turn this non-working
optimization on 4.1/4.2 (and 4.3 if nobody finds enough time RSN to actually
cure all problems with this pass; the opts.c change can be reverted easily
together with the patch that will fix it).

The separately attached tests (pr33136-[456].c) are just meant to show
what the optimization is really supposed to optimize and does not, I don't
want to commit them now.

Bootstrapped/regtested on x86_64-linux, ok for trunk/4.2/4.1?

2007-10-15  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/33136
	* opts.c (decode_options): Don't enable flag_ipa_type_escape.

	* gcc.c-torture/execute/20070824-1.c: New test.
	* gcc.dg/pr33136-1.c: New test.
	* gcc.dg/pr33136-2.c: New test.
	* gcc.dg/pr33136-3.c: New test.

--- gcc/opts.c.jj	2007-09-19 12:23:29.000000000 +0200
+++ gcc/opts.c	2007-10-15 15:19:21.000000000 +0200
@@ -830,7 +830,6 @@ decode_options (unsigned int argc, const
       flag_cse_follow_jumps = 1;
       flag_gcse = 1;
       flag_expensive_optimizations = 1;
-      flag_ipa_type_escape = 1;
       flag_rerun_cse_after_loop = 1;
       flag_caller_saves = 1;
       flag_peephole2 = 1;
--- gcc/testsuite/gcc.c-torture/execute/20070824-1.c.jj	2007-10-15 15:14:11.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/20070824-1.c	2007-10-15 15:14:11.000000000 +0200
@@ -0,0 +1,24 @@
+/* PR tree-optimization/33136 */
+
+extern void abort (void);
+
+struct S
+{
+  struct S *a;
+  int b;
+};
+
+int
+main (void)
+{
+  struct S *s = (struct S *) 0, **p, *n;
+  for (p = &s; *p; p = &(*p)->a);
+  n = (struct S *) __builtin_alloca (sizeof (*n));
+  n->a = *p;
+  n->b = 1;
+  *p = n;
+
+  if (!s)
+    abort ();
+  return 0;
+}
--- gcc/testsuite/gcc.dg/pr33136-2.c.jj	2007-10-15 15:14:11.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr33136-2.c	2007-10-15 15:14:11.000000000 +0200
@@ -0,0 +1,60 @@
+/* PR tree-optimization/33136 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern void abort (void);
+
+struct S
+{
+  void *a;
+  int b;
+  int *c;
+};
+static int d, e;
+
+static struct S s;
+
+static int *
+__attribute__((noinline, const))
+foo (void)
+{
+  return &s.b;
+}
+
+int *
+__attribute__((noinline))
+bar (int **f)
+{
+  s.c = &d;
+  *f = &e;
+  /* As nothing ever takes the address of any int * field in struct S,
+     the write to *f can't alias with the s.c field.  */
+  return s.c;
+}
+
+int
+__attribute__((noinline))
+baz (int *x)
+{
+  s.b = 1;
+  *x = 4;
+  /* Function foo takes address of an int field in struct S,
+     so *x can alias with the s.b field (and it does in this testcase).  */
+  return s.b;
+}
+
+int
+__attribute__((noinline))
+t (void)
+{
+  int *f = (int *) 0;
+  return 10 * (bar (&f) != &d) + baz (foo ());
+}
+
+int
+main (void)
+{
+  if (t () != 4)
+    abort ();
+  return 0;
+}
--- gcc/testsuite/gcc.dg/pr33136-1.c.jj	2007-10-15 15:14:11.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr33136-1.c	2007-10-15 15:14:11.000000000 +0200
@@ -0,0 +1,54 @@
+/* PR tree-optimization/33136 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern void abort (void);
+
+struct S
+{
+  struct S *a;
+  int b;
+  float f;
+};
+
+static struct S s;
+
+static int *
+__attribute__((noinline, const))
+foo (void)
+{
+  return &s.b;
+}
+
+float
+__attribute__((noinline))
+bar (float *f)
+{
+  s.f = 1.0;
+  *f = 4.0;
+  return s.f;
+}
+
+int
+__attribute__((noinline))
+baz (int *x)
+{
+  s.b = 1;
+  *x = 4;
+  return s.b;
+}
+
+int
+t (void)
+{
+  float f = 8.0;
+  return bar (&f) + baz (foo ());
+}
+
+int
+main (void)
+{
+  if (t () != 5)
+    abort ();
+  return 0;
+}
--- gcc/testsuite/gcc.dg/pr33136-3.c.jj	2007-10-15 15:14:11.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr33136-3.c	2007-10-15 15:14:11.000000000 +0200
@@ -0,0 +1,60 @@
+/* PR tree-optimization/33136 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern void abort (void);
+
+struct S
+{
+  void *a;
+  int b[3];
+  double *c;
+};
+static double d, e;
+
+static struct S s;
+
+static int *
+__attribute__((noinline, const))
+foo (void)
+{
+  return (int *) &s.b;
+}
+
+double *
+__attribute__((noinline))
+bar (double **f)
+{
+  s.c = &d;
+  *f = &e;
+  /* As nothing ever takes the address of any double * field in struct S,
+     the write to *f can't alias with the s.c field.  */
+  return s.c;
+}
+
+int
+__attribute__((noinline))
+baz (int *x)
+{
+  s.b[0] = 1;
+  *x = 4;
+  /* Function foo takes address of an int array field in struct S,
+     so *x can alias with the s.b field (and it does in this testcase).  */
+  return s.b[0];
+}
+
+int
+__attribute__((noinline))
+t (void)
+{
+  double *f = (double *) 0;
+  return 10 * (bar (&f) != &d) + baz (foo ());
+}
+
+int
+main (void)
+{
+  if (t () != 4)
+    abort ();
+  return 0;
+}

	Jakub

Attachment: N7
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]