Message ID | 54E730D4.1010403@suse.cz |
---|---|
State | New |
Headers | show |
> > Hi. > > This is second part which introduces better variable handling. Since readonly variable flag > identification can identify new candidates, ICF should filter out non-readonly variables in > execute phase. > > Ready for trunk? > Thanks, > Martin > >From a18a4840d14b1c0d35a9e4387daae29f5e8c906c Mon Sep 17 00:00:00 2001 > From: mliska <mliska@suse.cz> > Date: Fri, 20 Feb 2015 11:15:37 +0100 > Subject: [PATCH 2/2] Fix missed optimization for vars not marked by const. > > gcc/testsuite/ChangeLog: > > 2015-02-20 Martin Liska <mliska@suse.cz> > > * gcc.dg/ipa/ipa-icf-35.c: New test. > > gcc/ChangeLog: > > 2015-02-20 Martin Liska <mliska@suse.cz> > > * ipa-icf.c (sem_variable::parse): Ignore readonly flag that > should be evaluated in driver. > (sem_item_optimizer::filter_removed_items): Filter out > non-readonly variables. > --- > 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 859b9d1..5973b2f 100644 > --- a/gcc/ipa-icf.c > +++ b/gcc/ipa-icf.c > @@ -1228,10 +1228,6 @@ sem_variable::parse (varpool_node *node, bitmap_obstack *stack) > { > tree decl = node->decl; > > - 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); You want to remove can_handle test, too, because function may become static as effect of LTO. > @@ -1697,7 +1693,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)) Instead of readonly && can_handle you are doing now: bool readonly = TYPE_P (decl) ? TYPE_READONLY (decl) : TREE_READONLY (decl); bool can_handle = DECL_VIRTUAL_P (decl) || flag_merge_constants >= 2 || (!TREE_ADDRESSABLE (decl) && !node->externally_visible); please just test TREE_ADDRESSABLE (again do it late because var may become !TREE_ADDRESSABLE as a result of optimiziation) and varpool_node::ctor_useable_for_folding_p OK with this change. Honza
From a18a4840d14b1c0d35a9e4387daae29f5e8c906c Mon Sep 17 00:00:00 2001 From: mliska <mliska@suse.cz> Date: Fri, 20 Feb 2015 11:15:37 +0100 Subject: [PATCH 2/2] Fix missed optimization for vars not marked by const. gcc/testsuite/ChangeLog: 2015-02-20 Martin Liska <mliska@suse.cz> * gcc.dg/ipa/ipa-icf-35.c: New test. gcc/ChangeLog: 2015-02-20 Martin Liska <mliska@suse.cz> * ipa-icf.c (sem_variable::parse): Ignore readonly flag that should be evaluated in driver. (sem_item_optimizer::filter_removed_items): Filter out non-readonly variables. --- 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 859b9d1..5973b2f 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -1228,10 +1228,6 @@ sem_variable::parse (varpool_node *node, bitmap_obstack *stack) { tree decl = node->decl; - 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); @@ -1697,7 +1693,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