This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Use PTA info in pure-const pass.


On Thu, 2 Jul 2009, Jan Hubicka wrote:

> 
> Hi,
> this patch makes ipa-pure-const to use alias oracle to figure out if
> INDIRECT_REF is known to point only to local datastructures (and thus is valid
> for const&pure functions).
> 
> Testcase is attached, in practice this seems to match relatively few times
> (about 40 times in combine.c but it never actually makes difference as function
> contains some nonlocal stuff anyway), but it is easy thing to do and I hope it
> can make difference when stuff like iterators gets inlined.
> 
> Bootstrapped/regtested i686-linux, OK?
> Honza
> 	* gcc.dg/tree-ssa/local-pure-const.c: New testcase.
> 	* ipa-pure-const.c (check_op): Use PTA info to see if indirect_ref is
> 	local.
> Index: testsuite/gcc.dg/tree-ssa/local-pure-const.c
> ===================================================================
> *** testsuite/gcc.dg/tree-ssa/local-pure-const.c	(revision 0)
> --- testsuite/gcc.dg/tree-ssa/local-pure-const.c	(revision 0)
> ***************
> *** 0 ****
> --- 1,14 ----
> + /* { dg-do compile } */
> + /* { dg-options "-O1 -fdump-tree-local-pure-const1" } */
> + t(int a, int b, int c)
> + {
> +   int *p;
> +   if (a)
> +     p = &a;
> +   else
> +     p = &c;
> +   return *p;
> + }
> + /* { dg-final { scan-tree-dump-times "local memory is OK" 1 "local-pure-const1"} } */
> + /* { dg-final { scan-tree-dump-times "found to be const" 1 "local-pure-const1"} } */
> + /* { dg-final { cleanup-tree-dump "local-pure-const1" } } */
> Index: ipa-pure-const.c
> ===================================================================
> *** ipa-pure-const.c	(revision 149169)
> --- ipa-pure-const.c	(working copy)
> *************** check_decl (funct_state local, 
> *** 213,225 ****
>   static inline void 
>   check_op (funct_state local, tree t, bool checking_write)
>   {
> !   if (TREE_THIS_VOLATILE (t))
>       {
>         local->pure_const_state = IPA_NEITHER;
>         if (dump_file)
>   	fprintf (dump_file, "    Volatile indirect ref is not const/pure\n");
>         return;
>       }
>     else if (checking_write)
>       {
>         local->pure_const_state = IPA_NEITHER;
> --- 213,234 ----
>   static inline void 
>   check_op (funct_state local, tree t, bool checking_write)
>   {
> !   t = get_base_address (t);
> !   if (t && TREE_THIS_VOLATILE (t))
>       {
>         local->pure_const_state = IPA_NEITHER;
>         if (dump_file)
>   	fprintf (dump_file, "    Volatile indirect ref is not const/pure\n");
>         return;
>       }
> +   else if (t && TREE_CODE (t) == INDIRECT_REF

Use INDIRECT_REF_P (t).

Ok with that change.

Thanks,
Richard.

> + 	   && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
> + 	   && !ptr_deref_may_alias_global_p (TREE_OPERAND (t, 0)))
> +     {
> +       if (dump_file)
> + 	fprintf (dump_file, "    Indirect ref to local memory is OK\n");
> +       return;
> +     }
>     else if (checking_write)
>       {
>         local->pure_const_state = IPA_NEITHER;
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]