diff mbox

IPA ICF: add comparison for target and optimization nodes

Message ID 54AFACE6.4080907@suse.cz
State New
Headers show

Commit Message

Martin Liška Jan. 9, 2015, 10:26 a.m. UTC
On 01/09/2015 06:21 AM, Jeff Law wrote:
> On 01/07/15 04:38, Martin Liška wrote:
>> Hello.
>>
>> Following patch adds support for target and optimization nodes
>> comparison, which is
>> based on Honza's newly added infrastructure.
>>
>> Apart from that, there's a small hunk that corrects formatting and
>> removes unnecessary
>> call to a comparison function.
>>
>> Hope it can be applied as one patch.
>>
>> Tested on x86_64-linux-pc without any new regression introduction.
>>
>> Ready for trunk?
>>
>> Thank you,
>> Martin
>>
>> 0001-IPA-ICF-target-and-optimization-flags-comparison.patch
>>
>>
>>  From 393eaa47c8aef9a91a1c635016f23ca2f5aa25e4 Mon Sep 17 00:00:00 2001
>> From: mliska<mliska@suse.cz>
>> Date: Tue, 6 Jan 2015 15:06:18 +0100
>> Subject: [PATCH] IPA ICF: target and optimization flags comparison.
>>
>> gcc/ChangeLog:
>>
>> 2015-01-06  Martin Liska<mliska@suse.cz>
>>
>>     * cgraphunit.c (cgraph_node::create_wrapper): Fix level of indentation.
>>     * ipa-icf.c (sem_function::equals_private): Add support for target and
>>     (sem_item_optimizer::merge_classes): Remove redundant function
>>     comparison.
>>     optimization flags comparison.
>>     * tree.h (target_opts_for_fn): New function.
> Looks like the changelog is a bit goof'd with lines intermixed.
>
> Patch itself is good for the trunk.  It'd be nice if you could add a testcase as well.
>
> Jeff

Hi.

You are right, I forgot to delete a line in Changelog.
Attachment contains final version with a new test case I'm going to install.

Thanks,
Martin

Comments

Christophe Lyon Jan. 9, 2015, 4:11 p.m. UTC | #1
On 9 January 2015 at 11:26, Martin Liška <mliska@suse.cz> wrote:
> On 01/09/2015 06:21 AM, Jeff Law wrote:
>>
>> On 01/07/15 04:38, Martin Liška wrote:
>>>
>>> Hello.
>>>
>>> Following patch adds support for target and optimization nodes
>>> comparison, which is
>>> based on Honza's newly added infrastructure.
>>>
>>> Apart from that, there's a small hunk that corrects formatting and
>>> removes unnecessary
>>> call to a comparison function.
>>>
>>> Hope it can be applied as one patch.
>>>
>>> Tested on x86_64-linux-pc without any new regression introduction.
>>>
>>> Ready for trunk?
>>>
>>> Thank you,
>>> Martin
>>>
>>> 0001-IPA-ICF-target-and-optimization-flags-comparison.patch
>>>
>>>
>>>  From 393eaa47c8aef9a91a1c635016f23ca2f5aa25e4 Mon Sep 17 00:00:00 2001
>>> From: mliska<mliska@suse.cz>
>>> Date: Tue, 6 Jan 2015 15:06:18 +0100
>>> Subject: [PATCH] IPA ICF: target and optimization flags comparison.
>>>
>>> gcc/ChangeLog:
>>>
>>> 2015-01-06  Martin Liska<mliska@suse.cz>
>>>
>>>     * cgraphunit.c (cgraph_node::create_wrapper): Fix level of
>>> indentation.
>>>     * ipa-icf.c (sem_function::equals_private): Add support for target
>>> and
>>>     (sem_item_optimizer::merge_classes): Remove redundant function
>>>     comparison.
>>>     optimization flags comparison.
>>>     * tree.h (target_opts_for_fn): New function.
>>
>> Looks like the changelog is a bit goof'd with lines intermixed.
>>
>> Patch itself is good for the trunk.  It'd be nice if you could add a
>> testcase as well.
>>
>> Jeff
>
>
> Hi.
>
> You are right, I forgot to delete a line in Changelog.
> Attachment contains final version with a new test case I'm going to install.
>
Hi,

It looks like this patch broke GCC builds for ARM and AArch64 targets at least.

I see failures builds pr-support.o and unwind-arm.o:

0x10bb077 tree_check
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/tree.h:2778
0x10bb077 target_opts_for_fn
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/tree.h:4681
0x10bb077 ipa_icf::sem_function::equals_private(ipa_icf::sem_item*,
hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:431
0x10bbd27 ipa_icf::sem_function::equals(ipa_icf::sem_item*,
hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:386
0x10ba63a ipa_icf::sem_item_optimizer::subdivide_classes_by_equality(bool)
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:1893
0x10bcd86 ipa_icf::sem_item_optimizer::execute()
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:1712
0x10bce11 ipa_icf_driver
        /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:2441

(for target arm-none-eabi)

> Thanks,
> Martin
Kyrylo Tkachov Jan. 9, 2015, 5:32 p.m. UTC | #2
On 09/01/15 16:11, Christophe Lyon wrote:
> On 9 January 2015 at 11:26, Martin Liška <mliska@suse.cz> wrote:
>> On 01/09/2015 06:21 AM, Jeff Law wrote:
>>> On 01/07/15 04:38, Martin Liška wrote:
>>>> Hello.
>>>>
>>>> Following patch adds support for target and optimization nodes
>>>> comparison, which is
>>>> based on Honza's newly added infrastructure.
>>>>
>>>> Apart from that, there's a small hunk that corrects formatting and
>>>> removes unnecessary
>>>> call to a comparison function.
>>>>
>>>> Hope it can be applied as one patch.
>>>>
>>>> Tested on x86_64-linux-pc without any new regression introduction.
>>>>
>>>> Ready for trunk?
>>>>
>>>> Thank you,
>>>> Martin
>>>>
>>>> 0001-IPA-ICF-target-and-optimization-flags-comparison.patch
>>>>
>>>>
>>>>   From 393eaa47c8aef9a91a1c635016f23ca2f5aa25e4 Mon Sep 17 00:00:00 2001
>>>> From: mliska<mliska@suse.cz>
>>>> Date: Tue, 6 Jan 2015 15:06:18 +0100
>>>> Subject: [PATCH] IPA ICF: target and optimization flags comparison.
>>>>
>>>> gcc/ChangeLog:
>>>>
>>>> 2015-01-06  Martin Liska<mliska@suse.cz>
>>>>
>>>>      * cgraphunit.c (cgraph_node::create_wrapper): Fix level of
>>>> indentation.
>>>>      * ipa-icf.c (sem_function::equals_private): Add support for target
>>>> and
>>>>      (sem_item_optimizer::merge_classes): Remove redundant function
>>>>      comparison.
>>>>      optimization flags comparison.
>>>>      * tree.h (target_opts_for_fn): New function.
>>> Looks like the changelog is a bit goof'd with lines intermixed.
>>>
>>> Patch itself is good for the trunk.  It'd be nice if you could add a
>>> testcase as well.
>>>
>>> Jeff
>>
>> Hi.
>>
>> You are right, I forgot to delete a line in Changelog.
>> Attachment contains final version with a new test case I'm going to install.
>>
> Hi,
>
> It looks like this patch broke GCC builds for ARM and AArch64 targets at least.
>
> I see failures builds pr-support.o and unwind-arm.o:
>
> 0x10bb077 tree_check
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/tree.h:2778
> 0x10bb077 target_opts_for_fn
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/tree.h:4681
> 0x10bb077 ipa_icf::sem_function::equals_private(ipa_icf::sem_item*,
> hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:431
> 0x10bbd27 ipa_icf::sem_function::equals(ipa_icf::sem_item*,
> hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:386
> 0x10ba63a ipa_icf::sem_item_optimizer::subdivide_classes_by_equality(bool)
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:1893
> 0x10bcd86 ipa_icf::sem_item_optimizer::execute()
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:1712
> 0x10bce11 ipa_icf_driver
>          /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:2441
>
> (for target arm-none-eabi)

Yeah, I see these too when trying to bootstrap arm and aarch64

Kyrill

>
>> Thanks,
>> Martin
John David Anglin Jan. 10, 2015, 2:32 a.m. UTC | #3
On Fri, 09 Jan 2015, Kyrill Tkachov wrote:

>
> On 09/01/15 16:11, Christophe Lyon wrote:
>> On 9 January 2015 at 11:26, Martin Liška <mliska@suse.cz> wrote:
>>> On 01/09/2015 06:21 AM, Jeff Law wrote:
>>>> On 01/07/15 04:38, Martin Liška wrote:
>>>>> Hello.
>>>>>
>>>>> Following patch adds support for target and optimization nodes
>>>>> comparison, which is
>>>>> based on Honza's newly added infrastructure.
>>>>>
>>>>> Apart from that, there's a small hunk that corrects formatting and
>>>>> removes unnecessary
>>>>> call to a comparison function.
>>>>>
>>>>> Hope it can be applied as one patch.
>>>>>
>>>>> Tested on x86_64-linux-pc without any new regression introduction.
>>>>>
>>>>> Ready for trunk?
>>>>>
>>>>> Thank you,
>>>>> Martin
>>>>>
>>>>> 0001-IPA-ICF-target-and-optimization-flags-comparison.patch
>>>>>
>>>>>
>>>>>   From 393eaa47c8aef9a91a1c635016f23ca2f5aa25e4 Mon Sep 17 00:00:00 
>>>>> 2001
>>>>> From: mliska<mliska@suse.cz>
>>>>> Date: Tue, 6 Jan 2015 15:06:18 +0100
>>>>> Subject: [PATCH] IPA ICF: target and optimization flags comparison.
>>>>>
>>>>> gcc/ChangeLog:
>>>>>
>>>>> 2015-01-06  Martin Liska<mliska@suse.cz>
>>>>>
>>>>>      * cgraphunit.c (cgraph_node::create_wrapper): Fix level of
>>>>> indentation.
>>>>>      * ipa-icf.c (sem_function::equals_private): Add support for target
>>>>> and
>>>>>      (sem_item_optimizer::merge_classes): Remove redundant function
>>>>>      comparison.
>>>>>      optimization flags comparison.
>>>>>      * tree.h (target_opts_for_fn): New function.
>>>> Looks like the changelog is a bit goof'd with lines intermixed.
>>>>
>>>> Patch itself is good for the trunk.  It'd be nice if you could add a
>>>> testcase as well.
>>>>
>>>> Jeff
>>>
>>> Hi.
>>>
>>> You are right, I forgot to delete a line in Changelog.
>>> Attachment contains final version with a new test case I'm going to 
>>> install.
>>>
>> Hi,
>>
>> It looks like this patch broke GCC builds for ARM and AArch64 targets at 
>> least.
>>
>> I see failures builds pr-support.o and unwind-arm.o:
>>
>> 0x10bb077 tree_check
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/tree.h:2778
>> 0x10bb077 target_opts_for_fn
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/tree.h:4681
>> 0x10bb077 ipa_icf::sem_function::equals_private(ipa_icf::sem_item*,
>> hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:431
>> 0x10bbd27 ipa_icf::sem_function::equals(ipa_icf::sem_item*,
>> hash_map<symtab_node*, ipa_icf::sem_item*, default_hashmap_traits>&)
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:386
>> 0x10ba63a ipa_icf::sem_item_optimizer::subdivide_classes_by_equality(bool)
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:1893
>> 0x10bcd86 ipa_icf::sem_item_optimizer::execute()
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:1712
>> 0x10bce11 ipa_icf_driver
>>          
>> /tmp/2239141_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/gcc/ipa-icf.c:2441
>>
>> (for target arm-none-eabi)
>
> Yeah, I see these too when trying to bootstrap arm and aarch64

Also seen on hppa-hpux.

>
> Kyrill
>
>>
>>> Thanks,
>>> Martin
>

Dave
diff mbox

Patch

From 76f728dca65a266eb35bb5d96326f28e2147aafa Mon Sep 17 00:00:00 2001
From: mliska <mliska@suse.cz>
Date: Tue, 6 Jan 2015 15:06:18 +0100
Subject: [PATCH 1/2] IPA ICF: target and optimization flags comparison.

gcc/ChangeLog:

2015-01-06  Martin Liska  <mliska@suse.cz>

	* cgraphunit.c (cgraph_node::create_wrapper): Fix level of indentation.
	* ipa-icf.c (sem_function::equals_private): Add support for target and
	(sem_item_optimizer::merge_classes): Remove redundant function
	optimization flags comparison.
	* tree.h (target_opts_for_fn): New function.

gcc/testsuite/ChangeLog:

2015-01-09  Martin Liska  <mliska@suse.cz>

	* gcc.dg/ipa/ipa-icf-32.c: New test.
---
 gcc/cgraphunit.c                      | 52 +++++++++++++++++------------------
 gcc/ipa-icf.c                         | 44 ++++++++++++++++++++++++++++-
 gcc/testsuite/gcc.dg/ipa/ipa-icf-32.c | 24 ++++++++++++++++
 gcc/tree.h                            | 10 +++++++
 4 files changed, 103 insertions(+), 27 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/ipa-icf-32.c

diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index c8c8562..81246e2 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -2385,40 +2385,40 @@  cgraphunit_c_finalize (void)
 void
 cgraph_node::create_wrapper (cgraph_node *target)
 {
-    /* Preserve DECL_RESULT so we get right by reference flag.  */
-    tree decl_result = DECL_RESULT (decl);
+  /* Preserve DECL_RESULT so we get right by reference flag.  */
+  tree decl_result = DECL_RESULT (decl);
 
-    /* Remove the function's body but keep arguments to be reused
-       for thunk.  */
-    release_body (true);
-    reset ();
+  /* Remove the function's body but keep arguments to be reused
+     for thunk.  */
+  release_body (true);
+  reset ();
 
-    DECL_RESULT (decl) = decl_result;
-    DECL_INITIAL (decl) = NULL;
-    allocate_struct_function (decl, false);
-    set_cfun (NULL);
+  DECL_RESULT (decl) = decl_result;
+  DECL_INITIAL (decl) = NULL;
+  allocate_struct_function (decl, false);
+  set_cfun (NULL);
 
-    /* Turn alias into thunk and expand it into GIMPLE representation.  */
-    definition = true;
-    thunk.thunk_p = true;
-    thunk.this_adjusting = false;
+  /* Turn alias into thunk and expand it into GIMPLE representation.  */
+  definition = true;
+  thunk.thunk_p = true;
+  thunk.this_adjusting = false;
 
-    cgraph_edge *e = create_edge (target, NULL, 0, CGRAPH_FREQ_BASE);
+  cgraph_edge *e = create_edge (target, NULL, 0, CGRAPH_FREQ_BASE);
 
-    tree arguments = DECL_ARGUMENTS (decl);
+  tree arguments = DECL_ARGUMENTS (decl);
 
-    while (arguments)
-      {
-	TREE_ADDRESSABLE (arguments) = false;
-	arguments = TREE_CHAIN (arguments);
-      }
+  while (arguments)
+    {
+      TREE_ADDRESSABLE (arguments) = false;
+      arguments = TREE_CHAIN (arguments);
+    }
 
-    expand_thunk (false, true);
-    e->call_stmt_cannot_inline_p = true;
+  expand_thunk (false, true);
+  e->call_stmt_cannot_inline_p = true;
 
-    /* Inline summary set-up.  */
-    analyze ();
-    inline_analyze_function (this);
+  /* Inline summary set-up.  */
+  analyze ();
+  inline_analyze_function (this);
 }
 
 #include "gt-cgraphunit.h"
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index c7ba75a..28158b3 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -427,6 +427,49 @@  sem_function::equals_private (sem_item *item,
   if (!equals_wpa (item, ignored_nodes))
     return false;
 
+  /* Checking function TARGET and OPTIMIZATION flags.  */
+  cl_target_option *tar1 = target_opts_for_fn (decl);
+  cl_target_option *tar2 = target_opts_for_fn (m_compared_func->decl);
+
+  if (tar1 != NULL || tar2 != NULL)
+    {
+      if (!cl_target_option_eq (tar1, tar2))
+	{
+	  if (dump_file && (dump_flags & TDF_DETAILS))
+	    {
+	      fprintf (dump_file, "Source target flags\n");
+	      cl_target_option_print (dump_file, 2, tar1);
+	      fprintf (dump_file, "Target target flags\n");
+	      cl_target_option_print (dump_file, 2, tar2);
+	    }
+
+	  return return_false_with_msg ("Target flags are different");
+	}
+    }
+  else if (tar1 != NULL || tar2 != NULL)
+    return return_false_with_msg ("Target flags are different");
+
+  cl_optimization *opt1 = opts_for_fn (decl);
+  cl_optimization *opt2 = opts_for_fn (m_compared_func->decl);
+
+  if (opt1 != NULL && opt2 != NULL)
+    {
+      if (memcmp (opt1, opt2, sizeof(cl_optimization)))
+	{
+	  if (dump_file && (dump_flags & TDF_DETAILS))
+	    {
+	      fprintf (dump_file, "Source optimization flags\n");
+	      cl_optimization_print (dump_file, 2, opt1);
+	      fprintf (dump_file, "Target optimization flags\n");
+	      cl_optimization_print (dump_file, 2, opt2);
+	    }
+
+	  return return_false_with_msg ("optimization flags are different");
+	}
+    }
+  else if (opt1 != NULL || opt2 != NULL)
+    return return_false_with_msg ("optimization flags are different");
+
   /* Checking function arguments.  */
   tree decl1 = DECL_ATTRIBUTES (decl);
   tree decl2 = DECL_ATTRIBUTES (m_compared_func->decl);
@@ -2302,7 +2345,6 @@  sem_item_optimizer::merge_classes (unsigned int prev_class_count)
 	for (unsigned int j = 1; j < c->members.length (); j++)
 	  {
 	    sem_item *alias = c->members[j];
-	    source->equals (alias, m_symtab_node_map);
 
 	    if (dump_file)
 	      {
diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-32.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-32.c
new file mode 100644
index 0000000..22544a7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-32.c
@@ -0,0 +1,24 @@ 
+/* { dg-do run } */
+/* { dg-options "-O0 -fipa-icf -fdump-ipa-icf-details" } */
+
+int
+__attribute__((optimize("O0"), noinline, noclone))
+foo(int a)
+{
+  return a * a;
+}
+
+__attribute__ ((noinline, noclone))
+int bar(int b)
+{
+  return b * b;
+}
+
+int main()
+{
+  return foo (0) + bar (0);
+}
+
+/* { dg-final { scan-ipa-dump "optimization flags are different" "icf"  } } */
+/* { dg-final { scan-ipa-dump "Equal symbols: 0" "icf"  } } */
+/* { dg-final { cleanup-ipa-dump "icf" } } */
diff --git a/gcc/tree.h b/gcc/tree.h
index 3e74c7e..e9af9bf 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -4671,6 +4671,16 @@  opts_for_fn (const_tree fndecl)
   return TREE_OPTIMIZATION (fn_opts);
 }
 
+/* Return pointer to target flags of FNDECL.  */
+static inline cl_target_option *
+target_opts_for_fn (const_tree fndecl)
+{
+  tree fn_opts = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
+  if (fn_opts == NULL_TREE)
+    fn_opts = target_option_default_node;
+  return TREE_TARGET_OPTION (fn_opts);
+}
+
 /* opt flag for function FNDECL, e.g. opts_for_fn (fndecl, optimize) is
    the optimization level of function fndecl.  */
 #define opt_for_fn(fndecl, opt) (opts_for_fn (fndecl)->x_##opt)
-- 
2.1.2