public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* -fstrict-aliasing fixes 1/5: propagate -fno-strict-aliasing in the inliner
@ 2015-11-30 23:12 Jan Hubicka
  2015-12-01 20:52 ` Bernhard Reutner-Fischer
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Hubicka @ 2015-11-30 23:12 UTC (permalink / raw)
  To: gcc-patches

Hi,
this is first patch in the broken up series.  It adds the logic into
ipa-inline-transform to drop the flag when inlining.  I do it always until
we find a way to make early optimizations safe WRT this transform.

The testcase triggers with GCC 5.0/4.9 too, older compilers passes if
-fstrict-aliasing is used at linktime and fails otherwise.

Bootstrapped/regtested x86_64-linux, will commit it after re-testing on
Firefox.

Honza

	* ipa-inline-transform.c (inline_call): Drop -fstrict-aliasing when
	inlining -fno-strict-aliasing into -fstrict-aliasing body.
	* gcc.dg/lto/alias-1_0.c: New testcase.
	* gcc.dg/lto/alias-1_1.c: New testcase.
Index: ipa-inline-transform.c
===================================================================
--- ipa-inline-transform.c	(revision 231081)
+++ ipa-inline-transform.c	(working copy)
@@ -322,6 +322,21 @@ inline_call (struct cgraph_edge *e, bool
   if (DECL_FUNCTION_PERSONALITY (callee->decl))
     DECL_FUNCTION_PERSONALITY (to->decl)
       = DECL_FUNCTION_PERSONALITY (callee->decl);
+  if (!opt_for_fn (callee->decl, flag_strict_aliasing)
+      && opt_for_fn (to->decl, flag_strict_aliasing))
+    {
+      struct gcc_options opts = global_options;
+
+      cl_optimization_restore (&opts,
+	 TREE_OPTIMIZATION (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)));
+      opts.x_flag_strict_aliasing = false;
+      if (dump_file)
+	fprintf (dump_file, "Dropping flag_strict_aliasing on %s:%i\n",
+		 to->name (), to->order);
+      build_optimization_node (&opts);
+      DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
+	 = build_optimization_node (&opts);
+    }
 
   /* If aliases are involved, redirect edge to the actual destination and
      possibly remove the aliases.  */
Index: testsuite/gcc.dg/lto/alias-1_0.c
===================================================================
--- testsuite/gcc.dg/lto/alias-1_0.c	(revision 0)
+++ testsuite/gcc.dg/lto/alias-1_0.c	(revision 0)
@@ -0,0 +1,23 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O2 -flto } } } */
+int val;
+
+__attribute__ ((used))
+int *ptr = &val;
+__attribute__ ((used))
+float *ptr2 = (void *)&val;
+
+extern void typefun(float val);
+
+void link_error (void);
+
+int
+main()
+{ 
+  *ptr=1;
+  typefun (0);
+  if (*ptr)
+    __builtin_abort ();
+  return 0;
+}
+
Index: testsuite/gcc.dg/lto/alias-1_1.c
===================================================================
--- testsuite/gcc.dg/lto/alias-1_1.c	(revision 0)
+++ testsuite/gcc.dg/lto/alias-1_1.c	(revision 0)
@@ -0,0 +1,7 @@
+/* { dg-options "-fno-strict-aliasing" } */
+extern float *ptr2;
+void
+typefun (float val)
+{ 
+  *ptr2=val;
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -fstrict-aliasing fixes 1/5: propagate -fno-strict-aliasing in the inliner
  2015-11-30 23:12 -fstrict-aliasing fixes 1/5: propagate -fno-strict-aliasing in the inliner Jan Hubicka
@ 2015-12-01 20:52 ` Bernhard Reutner-Fischer
  2015-12-02  2:35   ` Jan Hubicka
  0 siblings, 1 reply; 3+ messages in thread
From: Bernhard Reutner-Fischer @ 2015-12-01 20:52 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches

On December 1, 2015 12:05:39 AM GMT+01:00, Jan Hubicka <hubicka@ucw.cz> wrote:
>Hi,
>this is first patch in the broken up series.  It adds the logic into
>ipa-inline-transform to drop the flag when inlining.  I do it always
>until
>we find a way to make early optimizations safe WRT this transform.
>
>The testcase triggers with GCC 5.0/4.9 too, older compilers passes if
>-fstrict-aliasing is used at linktime and fails otherwise.
>
>Bootstrapped/regtested x86_64-linux, will commit it after re-testing on
>Firefox.
>
>Honza
>
>	* ipa-inline-transform.c (inline_call): Drop -fstrict-aliasing when
>	inlining -fno-strict-aliasing into -fstrict-aliasing body.
>	* gcc.dg/lto/alias-1_0.c: New testcase.
>	* gcc.dg/lto/alias-1_1.c: New testcase.
>Index: ipa-inline-transform.c
>===================================================================
>--- ipa-inline-transform.c	(revision 231081)
>+++ ipa-inline-transform.c	(working copy)
>@@ -322,6 +322,21 @@ inline_call (struct cgraph_edge *e, bool
>   if (DECL_FUNCTION_PERSONALITY (callee->decl))
>     DECL_FUNCTION_PERSONALITY (to->decl)
>       = DECL_FUNCTION_PERSONALITY (callee->decl);
>+  if (!opt_for_fn (callee->decl, flag_strict_aliasing)
>+      && opt_for_fn (to->decl, flag_strict_aliasing))

Just curious why you don't handle the other way round?

>+    {
>+      struct gcc_options opts = global_options;
>+
>+      cl_optimization_restore (&opts,
>+	 TREE_OPTIMIZATION (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)));
>+      opts.x_flag_strict_aliasing = false;
>+      if (dump_file)
>+	fprintf (dump_file, "Dropping flag_strict_aliasing on %s:%i\n",
>+		 to->name (), to->order);

ISTR to have seen %s/%i for printing name and order in IPA, no?

>+      build_optimization_node (&opts);
>+      DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
>+	 = build_optimization_node (&opts);
>+    }
> 
>/* If aliases are involved, redirect edge to the actual destination and
>      possibly remove the aliases.  */
>Index: testsuite/gcc.dg/lto/alias-1_0.c
>===================================================================
>--- testsuite/gcc.dg/lto/alias-1_0.c	(revision 0)
>+++ testsuite/gcc.dg/lto/alias-1_0.c	(revision 0)
>@@ -0,0 +1,23 @@
>+/* { dg-lto-do run } */
>+/* { dg-lto-options { { -O2 -flto } } } */
>+int val;
>+
>+__attribute__ ((used))
>+int *ptr = &val;
>+__attribute__ ((used))
>+float *ptr2 = (void *)&val;
>+
>+extern void typefun(float val);
>+
>+void link_error (void);

Unused and unneeded forward decl?

Thanks,
>+
>+int
>+main()
>+{ 
>+  *ptr=1;
>+  typefun (0);
>+  if (*ptr)
>+    __builtin_abort ();
>+  return 0;
>+}
>+
>Index: testsuite/gcc.dg/lto/alias-1_1.c
>===================================================================
>--- testsuite/gcc.dg/lto/alias-1_1.c	(revision 0)
>+++ testsuite/gcc.dg/lto/alias-1_1.c	(revision 0)
>@@ -0,0 +1,7 @@
>+/* { dg-options "-fno-strict-aliasing" } */
>+extern float *ptr2;
>+void
>+typefun (float val)
>+{ 
>+  *ptr2=val;
>+}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -fstrict-aliasing fixes 1/5: propagate -fno-strict-aliasing in the inliner
  2015-12-01 20:52 ` Bernhard Reutner-Fischer
@ 2015-12-02  2:35   ` Jan Hubicka
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Hubicka @ 2015-12-02  2:35 UTC (permalink / raw)
  To: Bernhard Reutner-Fischer; +Cc: Jan Hubicka, gcc-patches

> >	* ipa-inline-transform.c (inline_call): Drop -fstrict-aliasing when
> >	inlining -fno-strict-aliasing into -fstrict-aliasing body.
> >	* gcc.dg/lto/alias-1_0.c: New testcase.
> >	* gcc.dg/lto/alias-1_1.c: New testcase.
> >Index: ipa-inline-transform.c
> >===================================================================
> >--- ipa-inline-transform.c	(revision 231081)
> >+++ ipa-inline-transform.c	(working copy)
> >@@ -322,6 +322,21 @@ inline_call (struct cgraph_edge *e, bool
> >   if (DECL_FUNCTION_PERSONALITY (callee->decl))
> >     DECL_FUNCTION_PERSONALITY (to->decl)
> >       = DECL_FUNCTION_PERSONALITY (callee->decl);
> >+  if (!opt_for_fn (callee->decl, flag_strict_aliasing)
> >+      && opt_for_fn (to->decl, flag_strict_aliasing))
> 
> Just curious why you don't handle the other way round?

After inlining, opt_for_fn of CALLEE will be ignored and will
become opt_for_fn of TO. Turning flag_strict_alising code to
!flag_strict_aliasing is safe, but not the other way around.
> 
> >+    {
> >+      struct gcc_options opts = global_options;
> >+
> >+      cl_optimization_restore (&opts,
> >+	 TREE_OPTIMIZATION (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)));
> >+      opts.x_flag_strict_aliasing = false;
> >+      if (dump_file)
> >+	fprintf (dump_file, "Dropping flag_strict_aliasing on %s:%i\n",
> >+		 to->name (), to->order);
> 
> ISTR to have seen %s/%i for printing name and order in IPA, no?

Hmm, right, will update it.
> >+void link_error (void);
> 
> Unused and unneeded forward decl?

Yep, I originally wanted to check that we optimize out the type punned code (we can)
but we don't seem to be able to do so.   It is just a testcase and extra
declaration is harmless I guess.

Thanks!
Honza

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-02  2:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30 23:12 -fstrict-aliasing fixes 1/5: propagate -fno-strict-aliasing in the inliner Jan Hubicka
2015-12-01 20:52 ` Bernhard Reutner-Fischer
2015-12-02  2:35   ` Jan Hubicka

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).