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: [tree-ssa] dead const/pure/alloca call removal


Hello,

> this patch allows us to remove dead constant and pure function calls.  In
> addition it eliminates alloca calls.  I am not sure whether some other non-pure
> builtins can be removed too...
> How far we are from elliminating calls in LIBCALL blocks now?
> 
> /* { dg-do compile } */
> /* { dg-options "-O1 -fdump-tree-dce2" } */
> 
> int t() __attribute__ ((const));
> q()
> {
>   int i = t();
>   if (!i)
>     i = t();
> }
> /* There should be no IF conditionals.  */
> /* { dg-final { scan-tree-dump-times "if " 0 "dce2"} } */
>  
> 	* tree-ssa-dce.c (call_usefull_p): New function.
> 	(stmt_useful_p):  Use it.
> Index: tree-ssa-dce.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dce.c,v
> retrieving revision 1.1.2.64
> diff -c -3 -p -r1.1.2.64 tree-ssa-dce.c
> *** tree-ssa-dce.c	5 Nov 2003 13:39:23 -0000	1.1.2.64
> --- tree-ssa-dce.c	8 Nov 2003 17:02:53 -0000
> *************** find_useful_stmts (void)
> *** 236,241 ****
> --- 236,258 ----
>       }
>   }
>   
> + /* Return false when CALL can be removed when it's return value is dead.
> +    In addition to const and pure functions we may elliminate alloca 
> +    builtin too.  */
> + static bool
> + call_usefull_p (tree call)
> + {
> +   tree decl;
> +   int flags = call_expr_flags (call);
> + 
> +   if (flags & (ECF_CONST | ECF_PURE))
> +     return false;
> +   decl = get_callee_fndecl (call);
> +   if (decl && DECL_BUILT_IN (decl)
> +       && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
> +     return true;
        ^^^^^^^^^^^^

you probably want return false here.

> +   return true;
> + }

Zdenek


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