public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Walk through thunks when propagating comdat group
@ 2015-04-07 14:35 Ilya Enkovich
  2015-04-07 20:37 ` Jan Hubicka
  0 siblings, 1 reply; 3+ messages in thread
From: Ilya Enkovich @ 2015-04-07 14:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: hubicka

Hi,

Currently enqueue_references in comdats pass enqueue target function instead of thunks.  But propagate_comdat_group doesn't walk through thunks and therefore comdat group of thunk's caller is not propagated into thunk's target function.  This patch tries to fix it.  Testing is in progress.  Does it look OK?

Thanks,
Ilya
--
gcc/

2015-04-07  Ilya Enkovich  <ilya.enkovich@intel.com>

	* ipa-comdats.c (propagate_comdat_group): Walk through thunks.

gcc/testsuite/

2015-04-07  Ilya Enkovich  <ilya.enkovich@intel.com>

	* gcc.target/i386/mpx/chkp-thunk-comdat-3.c: New.


diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c
index f349f9f..74088a9 100644
--- a/gcc/ipa-comdats.c
+++ b/gcc/ipa-comdats.c
@@ -144,10 +144,12 @@ propagate_comdat_group (struct symtab_node *symbol,
 
 	/* If we see inline clone, its comdat group actually
 	   corresponds to the comdat group of the function it is inlined
-	   to.  */
+	   to.  Dive into thunks similar to aliases. */
 
 	if (cgraph_node * cn = dyn_cast <cgraph_node *> (symbol2))
 	  {
+	    if (cn->thunk.thunk_p)
+	      newgroup = propagate_comdat_group (symbol2, newgroup, map);
 	    if (cn->global.inlined_to)
 	      symbol2 = cn->global.inlined_to;
 	  }
diff --git a/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c
new file mode 100644
index 0000000..dd0057e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -O -fvisibility=hidden" } */
+
+int val;
+
+static int __attribute__((noinline))
+test1 ()
+{
+  return val;
+}
+
+static int __attribute__((bnd_legacy,noinline))
+test2 ()
+{
+  return test1 ();
+}
+
+int
+test3 (void)
+{
+  return test2 ();
+}
+

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

* Re: [PATCH] Walk through thunks when propagating comdat group
  2015-04-07 14:35 [PATCH] Walk through thunks when propagating comdat group Ilya Enkovich
@ 2015-04-07 20:37 ` Jan Hubicka
  2015-04-08 13:48   ` Ilya Enkovich
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Hubicka @ 2015-04-07 20:37 UTC (permalink / raw)
  To: Ilya Enkovich; +Cc: gcc-patches, hubicka

> Hi,
> 
> Currently enqueue_references in comdats pass enqueue target function instead of thunks.  But propagate_comdat_group doesn't walk through thunks and therefore comdat group of thunk's caller is not propagated into thunk's target function.  This patch tries to fix it.  Testing is in progress.  Does it look OK?
> 
> Thanks,
> Ilya
> --
> gcc/
> 
> 2015-04-07  Ilya Enkovich  <ilya.enkovich@intel.com>
> 
> 	* ipa-comdats.c (propagate_comdat_group): Walk through thunks.
> 
> gcc/testsuite/
> 
> 2015-04-07  Ilya Enkovich  <ilya.enkovich@intel.com>
> 
> 	* gcc.target/i386/mpx/chkp-thunk-comdat-3.c: New.
> 
> 
> diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c
> index f349f9f..74088a9 100644
> --- a/gcc/ipa-comdats.c
> +++ b/gcc/ipa-comdats.c
> @@ -144,10 +144,12 @@ propagate_comdat_group (struct symtab_node *symbol,
>  
>  	/* If we see inline clone, its comdat group actually
>  	   corresponds to the comdat group of the function it is inlined
> -	   to.  */
> +	   to.  Dive into thunks similar to aliases. */
>  
>  	if (cgraph_node * cn = dyn_cast <cgraph_node *> (symbol2))
>  	  {
> +	    if (cn->thunk.thunk_p)
> +	      newgroup = propagate_comdat_group (symbol2, newgroup, map);

OK, thanks!
Please put the comment about inline clones just before the global.inlined_to test
and make the comment about thunks separate.
Probably "Thunks can not call across section boundary"

Honza
>  	    if (cn->global.inlined_to)
>  	      symbol2 = cn->global.inlined_to;
>  	  }
> diff --git a/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c
> new file mode 100644
> index 0000000..dd0057e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c
> @@ -0,0 +1,23 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fcheck-pointer-bounds -mmpx -O -fvisibility=hidden" } */
> +
> +int val;
> +
> +static int __attribute__((noinline))
> +test1 ()
> +{
> +  return val;
> +}
> +
> +static int __attribute__((bnd_legacy,noinline))
> +test2 ()
> +{
> +  return test1 ();
> +}
> +
> +int
> +test3 (void)
> +{
> +  return test2 ();
> +}
> +

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

* Re: [PATCH] Walk through thunks when propagating comdat group
  2015-04-07 20:37 ` Jan Hubicka
@ 2015-04-08 13:48   ` Ilya Enkovich
  0 siblings, 0 replies; 3+ messages in thread
From: Ilya Enkovich @ 2015-04-08 13:48 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

On 07 Apr 22:37, Jan Hubicka wrote:
> 
> OK, thanks!
> Please put the comment about inline clones just before the global.inlined_to test
> and make the comment about thunks separate.
> Probably "Thunks can not call across section boundary"
> 
> Honza

Here is a committed variant.

Thanks,
Ilya
--
gcc/

2015-04-08  Ilya Enkovich  <ilya.enkovich@intel.com>

	* ipa-comdats.c (propagate_comdat_group): Walk through thunks.

gcc/testsuite/

2015-04-08  Ilya Enkovich  <ilya.enkovich@intel.com>

	* gcc.target/i386/mpx/chkp-thunk-comdat-3.c: New.


diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c
index f349f9f..4298b9b 100644
--- a/gcc/ipa-comdats.c
+++ b/gcc/ipa-comdats.c
@@ -142,12 +142,14 @@ propagate_comdat_group (struct symtab_node *symbol,
       {
 	struct symtab_node *symbol2 = edge->caller;
 
-	/* If we see inline clone, its comdat group actually
-	   corresponds to the comdat group of the function it is inlined
-	   to.  */
-
 	if (cgraph_node * cn = dyn_cast <cgraph_node *> (symbol2))
 	  {
+	    /* Thunks can not call across section boundary.  */
+	    if (cn->thunk.thunk_p)
+	      newgroup = propagate_comdat_group (symbol2, newgroup, map);
+	    /* If we see inline clone, its comdat group actually
+	       corresponds to the comdat group of the function it
+	       is inlined to.  */
 	    if (cn->global.inlined_to)
 	      symbol2 = cn->global.inlined_to;
 	  }
diff --git a/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c
new file mode 100644
index 0000000..dd0057e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/chkp-thunk-comdat-3.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -O -fvisibility=hidden" } */
+
+int val;
+
+static int __attribute__((noinline))
+test1 ()
+{
+  return val;
+}
+
+static int __attribute__((bnd_legacy,noinline))
+test2 ()
+{
+  return test1 ();
+}
+
+int
+test3 (void)
+{
+  return test2 ();
+}
+

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

end of thread, other threads:[~2015-04-08 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07 14:35 [PATCH] Walk through thunks when propagating comdat group Ilya Enkovich
2015-04-07 20:37 ` Jan Hubicka
2015-04-08 13:48   ` Ilya Enkovich

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