public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] ICF: move readonly decision for variables to the right place
@ 2015-03-01  0:15 Martin Liška
  2015-03-01  0:26 ` Jan Hubicka
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Liška @ 2015-03-01  0:15 UTC (permalink / raw)
  To: gcc-pat >> GCC Patches; +Cc: hubicka >> Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 188 bytes --]

Hello.

This patch makes correctly decision about variables that are read-only and are candidates
for merge operation. Tested on x86_64-unknown-linux-gnu.

Ready for trunk?
Thanks,
Martin

[-- Attachment #2: 0003-ICF-Optimize-variable-merging.patch --]
[-- Type: text/x-patch, Size: 2670 bytes --]

From 72370368eb04a69bf36b42f692d44c21592bc94a Mon Sep 17 00:00:00 2001
From: mliska <mliska@suse.cz>
Date: Fri, 27 Feb 2015 23:44:32 +0100
Subject: [PATCH 3/4] ICF: Optimize variable merging.

gcc/ChangeLog:

2015-02-28  Martin Liska  <mliska@suse.cz>
	    Jan Hubicka   <hubicka@ucw.cz>

	* ipa-icf.c (sem_variable::parse): Do not filter variables
	too early.
	(sem_item_optimizer::filter_removed_items): Filter out correct
	readonly variables.

gcc/testsuite/ChangeLog:

2015-02-28  Martin Liska  <mliska@suse.cz>
	    Jan Hubicka   <hubicka@ucw.cz>

	* gcc.dg/ipa/ipa-icf-35.c: New test.
---
 gcc/ipa-icf.c                         | 13 ++++++++-----
 gcc/testsuite/gcc.dg/ipa/ipa-icf-35.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-icf-35.c

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 864a5d0..5b1fcff 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -1410,10 +1410,6 @@ sem_variable::parse (varpool_node *node, bitmap_obstack *stack)
   if (node->alias)
     return NULL;
 
-  bool readonly = TYPE_P (decl) ? TYPE_READONLY (decl) : TREE_READONLY (decl);
-  if (!readonly)
-    return NULL;
-
   bool can_handle = DECL_VIRTUAL_P (decl)
 		    || flag_merge_constants >= 2
 		    || (!TREE_ADDRESSABLE (decl) && !node->externally_visible);
@@ -1900,7 +1896,14 @@ sem_item_optimizer::filter_removed_items (void)
 	  if (!flag_ipa_icf_variables)
 	    remove_item (item);
 	  else
-	    filtered.safe_push (item);
+	    {
+	      /* Filter out non-readonly variables.  */
+	      tree decl = item->decl;
+	      if (TYPE_P (decl) ? TYPE_READONLY (decl) : TREE_READONLY (decl))
+		filtered.safe_push (item);
+	      else
+		remove_item (item);
+	    }
         }
     }
 
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-35.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-35.c
new file mode 100644
index 0000000..95d247e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-35.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-ipa-icf"  } */
+
+#include <stdlib.h>
+#include <assert.h>
+
+void f1()
+{
+}
+
+void f2()
+{
+}
+
+static void (*a)(void)=&f1;
+static void (*b)(void)=&f1;
+static void (*c)(void)=&f2;
+static void (*d)(void)=&f2;
+
+int main()
+{
+  a();
+  b();
+  c();
+  d();
+
+  return 0;
+}
+
+/* { dg-final { scan-ipa-dump "Equal symbols: 3" "icf"  } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:f2->f1" "icf"  } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:d->c" "icf"  } } */
+/* { dg-final { scan-ipa-dump "Semantic equality hit:b->a" "icf"  } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
-- 
2.1.2



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

end of thread, other threads:[~2015-03-06 19:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-01  0:15 [PATCH] ICF: move readonly decision for variables to the right place Martin Liška
2015-03-01  0:26 ` Jan Hubicka
2015-03-02  0:58   ` Jan Hubicka
2015-03-02  7:53     ` Jan Hubicka
2015-03-02  9:47       ` Martin Liška
2015-03-06 14:38       ` H.J. Lu
2015-03-06 19:08         ` 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).