diff mbox

Reload global options when strict aliasing is dropped (PR ipa/79043).

Message ID e19c330a-4f36-bd2a-b739-ceb9f82db131@suse.cz
State Accepted
Commit 77719b0675a248bcf9cb0876a86e80ca54979601
Headers show

Commit Message

Martin Liška Jan. 10, 2017, 3:28 p.m. UTC
As mentioned in the PR, we currently do not properly reload global
optimization options when we drop strict-aliasing flag on a function
that equals to cfun.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

Comments

Richard Biener Jan. 13, 2017, 12:16 p.m. UTC | #1
On Tue, Jan 10, 2017 at 4:28 PM, Martin Liška <mliska@suse.cz> wrote:
> As mentioned in the PR, we currently do not properly reload global

> optimization options when we drop strict-aliasing flag on a function

> that equals to cfun.

>

> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>

> Ready to be installed?


Ok.

Richard.

> Martin
Martin Liška Jan. 13, 2017, 1 p.m. UTC | #2
On 01/13/2017 01:16 PM, Richard Biener wrote:
> On Tue, Jan 10, 2017 at 4:28 PM, Martin Liška <mliska@suse.cz> wrote:

>> As mentioned in the PR, we currently do not properly reload global

>> optimization options when we drop strict-aliasing flag on a function

>> that equals to cfun.

>>

>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>>

>> Ready to be installed?

> 

> Ok.


Thanks, applied to trunk. May I install the patch to active branches if it survives
bootstrap and regression tests?

Martin

> 

> Richard.

> 

>> Martin
Richard Biener Jan. 13, 2017, 1:01 p.m. UTC | #3
On Fri, Jan 13, 2017 at 2:00 PM, Martin Liška <mliska@suse.cz> wrote:
> On 01/13/2017 01:16 PM, Richard Biener wrote:

>> On Tue, Jan 10, 2017 at 4:28 PM, Martin Liška <mliska@suse.cz> wrote:

>>> As mentioned in the PR, we currently do not properly reload global

>>> optimization options when we drop strict-aliasing flag on a function

>>> that equals to cfun.

>>>

>>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>>>

>>> Ready to be installed?

>>

>> Ok.

>

> Thanks, applied to trunk. May I install the patch to active branches if it survives

> bootstrap and regression tests?


Yes, but please wait a few days to see if there's any fallout with odd
target stuff
done by set_cfun.

Richard.

>

> Martin

>

>>

>> Richard.

>>

>>> Martin

>
Martin Liška Jan. 17, 2017, 3:15 p.m. UTC | #4
On 01/13/2017 02:01 PM, Richard Biener wrote:
> On Fri, Jan 13, 2017 at 2:00 PM, Martin Liška <mliska@suse.cz> wrote:

>> On 01/13/2017 01:16 PM, Richard Biener wrote:

>>> On Tue, Jan 10, 2017 at 4:28 PM, Martin Liška <mliska@suse.cz> wrote:

>>>> As mentioned in the PR, we currently do not properly reload global

>>>> optimization options when we drop strict-aliasing flag on a function

>>>> that equals to cfun.

>>>>

>>>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

>>>>

>>>> Ready to be installed?

>>>

>>> Ok.

>>

>> Thanks, applied to trunk. May I install the patch to active branches if it survives

>> bootstrap and regression tests?

> 

> Yes, but please wait a few days to see if there's any fallout with odd

> target stuff

> done by set_cfun.


Ok, looks there's no fallout. To install the patch to GCC-5 branch I need patch from
r231095, which I tested with this patch and works fine.

Honza is it OK to apply it together?
Thanks,
Martin


> 

> Richard.

> 

>>

>> Martin

>>

>>>

>>> Richard.

>>>

>>>> Martin

>>
diff mbox

Patch

From 53108a01c5fcb6fcfca15b389e76217b724915c3 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 10 Jan 2017 14:43:04 +0100
Subject: [PATCH] Reload global options when strict aliasing is dropped (PR
 ipa/79043).

gcc/ChangeLog:

2017-01-10  Martin Liska  <mliska@suse.cz>

	PR ipa/79043
	* function.c (set_cfun): Add new argument force.
	* function.h (set_cfun): Likewise.
	* ipa-inline-transform.c (inline_call): Use the function when
	strict alising from is dropped for function we inline to.

gcc/testsuite/ChangeLog:

2017-01-10  Martin Liska  <mliska@suse.cz>

	PR ipa/79043
	* gcc.c-torture/execute/pr79043.c: New test.
---
 gcc/function.c                                |  4 ++--
 gcc/function.h                                |  2 +-
 gcc/ipa-inline-transform.c                    |  8 ++++++++
 gcc/testsuite/gcc.c-torture/execute/pr79043.c | 21 +++++++++++++++++++++
 4 files changed, 32 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr79043.c

diff --git a/gcc/function.c b/gcc/function.c
index 7fde96adbe3..f625489205b 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4811,9 +4811,9 @@  invoke_set_current_function_hook (tree fndecl)
 /* cfun should never be set directly; use this function.  */
 
 void
-set_cfun (struct function *new_cfun)
+set_cfun (struct function *new_cfun, bool force)
 {
-  if (cfun != new_cfun)
+  if (cfun != new_cfun || force)
     {
       cfun = new_cfun;
       invoke_set_current_function_hook (new_cfun ? new_cfun->decl : NULL_TREE);
diff --git a/gcc/function.h b/gcc/function.h
index fb3cbbc3346..fb8f57ae385 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -613,7 +613,7 @@  extern tree block_chainon (tree, tree);
 extern void number_blocks (tree);
 
 /* cfun shouldn't be set directly; use one of these functions instead.  */
-extern void set_cfun (struct function *new_cfun);
+extern void set_cfun (struct function *new_cfun, bool force = false);
 extern void push_cfun (struct function *new_cfun);
 extern void pop_cfun (void);
 
diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c
index 7725fadd6d8..a8e73cd6967 100644
--- a/gcc/ipa-inline-transform.c
+++ b/gcc/ipa-inline-transform.c
@@ -340,6 +340,8 @@  inline_call (struct cgraph_edge *e, bool update_original,
   if (DECL_FUNCTION_PERSONALITY (callee->decl))
     DECL_FUNCTION_PERSONALITY (to->decl)
       = DECL_FUNCTION_PERSONALITY (callee->decl);
+
+  bool reload_optimization_node = false;
   if (!opt_for_fn (callee->decl, flag_strict_aliasing)
       && opt_for_fn (to->decl, flag_strict_aliasing))
     {
@@ -352,6 +354,7 @@  inline_call (struct cgraph_edge *e, bool update_original,
 		 to->name (), to->order);
       DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
 	 = build_optimization_node (&opts);
+      reload_optimization_node = true;
     }
 
   inline_summary *caller_info = inline_summaries->get (to);
@@ -412,9 +415,14 @@  inline_call (struct cgraph_edge *e, bool update_original,
 		     callee->name (), callee->order, to->name (), to->order);
 	  DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl)
 	     = build_optimization_node (&opts);
+	  reload_optimization_node = true;
 	}
     }
 
+  /* Reload global optimization flags.  */
+  if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun)
+    set_cfun (cfun, true);
+
   /* If aliases are involved, redirect edge to the actual destination and
      possibly remove the aliases.  */
   if (e->callee != callee)
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr79043.c b/gcc/testsuite/gcc.c-torture/execute/pr79043.c
new file mode 100644
index 00000000000..b7fcc8260dc
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr79043.c
@@ -0,0 +1,21 @@ 
+/* PR ipa/78791 */
+
+int val;
+
+int *ptr = &val;
+float *ptr2 = &val;
+
+static
+__attribute__((always_inline, optimize ("-fno-strict-aliasing")))
+typepun ()
+{
+  *ptr2=0;
+}
+
+main()
+{
+  *ptr=1;
+  typepun ();
+  if (*ptr)
+    __builtin_abort ();
+}
-- 
2.11.0