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]

[tree-ssa] dead const/pure/alloca call removal


Hi,
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;
+   return true;
+ }
  
  /* Return true if STMT is necessary.  */
  
*************** stmt_useful_p (tree stmt)
*** 258,270 ****
      case CASE_LABEL_EXPR:
      case LABEL_EXPR:
      case BIND_EXPR:
-     case CALL_EXPR:
      case RESX_EXPR:
        return true;
  
      case MODIFY_EXPR:
        if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
! 	return true;
  
        /* These values are mildly magic bits of the EH runtime.  We can't
  	 see the entire lifetime of these values until landing pads are
--- 275,288 ----
      case CASE_LABEL_EXPR:
      case LABEL_EXPR:
      case BIND_EXPR:
      case RESX_EXPR:
        return true;
+     case CALL_EXPR:
+       return call_usefull_p (stmt);
  
      case MODIFY_EXPR:
        if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR
! 	  && call_usefull_p (TREE_OPERAND (stmt, 1)))
! 	return true;
  
        /* These values are mildly magic bits of the EH runtime.  We can't
  	 see the entire lifetime of these values until landing pads are


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