> 
> 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 <mli...@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  <mli...@suse.cz>
> 
>       * gcc.dg/ipa/ipa-icf-35.c: New test.
> 
> gcc/ChangeLog:
> 
> 2015-02-20  Martin Liska  <mli...@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

Reply via email to