On Mon, 23 Jun 2014, Jan Hubicka wrote:

> Hi,
> this is patch to add the used_by_single_function flag to varpool.  In full 
> generality
> it is a simple dataflow problem, since the variable may be referred by other 
> variables
> as long as all of them are used by one function only.  I have 
> bootstrapped/regtested it
> on x86_64-linux and lto-bootstrapped with the following variant of earlier 
> Richard's
> patch to tree-ssa-dce:
> Index: tree-ssa-dce.c
> ===================================================================
> --- tree-ssa-dce.c    (revision 211881)
> +++ tree-ssa-dce.c    (working copy)
> @@ -73,6 +73,7 @@ along with GCC; see the file COPYING3.
>  #include "flags.h"
>  #include "cfgloop.h"
>  #include "tree-scalar-evolution.h"
> +#include "cgraph.h"
>  
>  static struct stmt_stats
>  {
> @@ -278,10 +279,21 @@ mark_stmt_if_obviously_necessary (gimple
>        break;
>  
>      case GIMPLE_ASSIGN:
> -      if (TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME
> -       && TREE_CLOBBER_P (gimple_assign_rhs1 (stmt)))
> -     return;
> -      break;
> +      {
> +     tree lhs = gimple_assign_lhs (stmt);
> +     if (TREE_CODE (lhs) == SSA_NAME
> +         && TREE_CLOBBER_P (gimple_assign_rhs1 (stmt)))
> +       return;
> +     lhs = get_base_address (lhs);
> +     if (TREE_CODE (lhs) == VAR_DECL
> +         && !TREE_ADDRESSABLE (lhs)
> +         && !DECL_NONALIASED (lhs)
> +         && !TREE_THIS_VOLATILE (lhs)
> +         && (TREE_STATIC (lhs) || DECL_EXTERNAL (lhs))
> +         && varpool_node_for_decl (lhs)->used_by_single_function)
> +       return;
> +     break;
> +      }
>  
>      default:
>        break;
> 
> I will keep the dce change to Richard - in full generality we may want to
> handle asm statements (that seems to be all considered volatile by current
> implementation) and calls, too.

Damn, the DCE algorithm doesn't really handle the situation.

int foo ()
{
  static int i;
  if (i++)
    return i;
  return 0;
}

  <bb 2>:
  i.0_3 = i;
  i.2_4 = i.0_3 + 1;
  i = i.2_4;
  if (i.0_3 != 0)

and DCE will happily remove the store i = i.2_4 as there is no
user downstream (it of course doesn't need to consider upstream
uses).

So we can't really wire it into the propagator this way unless
we first compute if there is _any_ read of the decl in the
function (that is, if the decl is write-only).  Maybe we want
to special-case those globals in the propagator though (the
use may be dead after all).

So, more work needed, queued.

Richard.

Reply via email to