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]

[PATCH] Speedup gimple_assign_rhs_code, inline gimple_assign_single_p


I noticed that gimple_assign_rhs_code is written in a non-optimal
way, using a helper that isn't suited for such a basic operation.
On the way I simplified some other predicates, inlined 
gimple_assign_single_p and removed the somewhat odd is_gimple_cast
helper.

Bootstrapped and tested on x86_64-unknown-linux-gnu, committed.

Richard.

2010-11-27  Richard Guenther  <rguenther@suse.de>

	* gimple.c (gimple_assign_copy_p): Use gimple_assign_single_p.
	(gimple_assign_ssa_name_copy_p): Likewise.
	(gimple_assign_unary_nop_p): Use is_gimple_assign.
	(is_gimple_cast): Remove.
	(gimple_assign_single_p): Move ...
	* gimple.h (gimple_assign_single_p): ... here.
	(is_gimple_cast): Remove.
	(gimple_assign_rhs_code): Simplify.
	* gimple-fold.c (gimple_fold_builtin): Use CONVERT_EXPR_P
	instead of is_gimple_cast.
	* ipa-type-escape.c (look_for_casts): Likewise.

Index: gcc/gimple.c
===================================================================
*** gcc/gimple.c	(revision 167187)
--- gcc/gimple.c	(working copy)
*************** gimple_call_return_flags (const_gimple s
*** 1873,1887 ****
      }
  }
  
  /* Return true if GS is a copy assignment.  */
  
  bool
  gimple_assign_copy_p (gimple gs)
  {
!   return gimple_code (gs) == GIMPLE_ASSIGN
!          && get_gimple_rhs_class (gimple_assign_rhs_code (gs))
! 	    == GIMPLE_SINGLE_RHS
! 	 && is_gimple_val (gimple_op (gs, 1));
  }
  
  
--- 1873,1886 ----
      }
  }
  
+ 
  /* Return true if GS is a copy assignment.  */
  
  bool
  gimple_assign_copy_p (gimple gs)
  {
!   return (gimple_assign_single_p (gs)
! 	  && is_gimple_val (gimple_op (gs, 1)));
  }
  
  
*************** gimple_assign_copy_p (gimple gs)
*** 1890,1917 ****
  bool
  gimple_assign_ssa_name_copy_p (gimple gs)
  {
!   return (gimple_code (gs) == GIMPLE_ASSIGN
! 	  && (get_gimple_rhs_class (gimple_assign_rhs_code (gs))
! 	      == GIMPLE_SINGLE_RHS)
  	  && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
  	  && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
  }
  
  
- /* Return true if GS is an assignment with a singleton RHS, i.e.,
-    there is no operator associated with the assignment itself.
-    Unlike gimple_assign_copy_p, this predicate returns true for
-    any RHS operand, including those that perform an operation
-    and do not have the semantics of a copy, such as COND_EXPR.  */
- 
- bool
- gimple_assign_single_p (gimple gs)
- {
-   return (gimple_code (gs) == GIMPLE_ASSIGN
-           && get_gimple_rhs_class (gimple_assign_rhs_code (gs))
- 	     == GIMPLE_SINGLE_RHS);
- }
- 
  /* Return true if GS is an assignment with a unary RHS, but the
     operator has no effect on the assigned value.  The logic is adapted
     from STRIP_NOPS.  This predicate is intended to be used in tuplifying
--- 1889,1900 ----
  bool
  gimple_assign_ssa_name_copy_p (gimple gs)
  {
!   return (gimple_assign_single_p (gs)
  	  && TREE_CODE (gimple_assign_lhs (gs)) == SSA_NAME
  	  && TREE_CODE (gimple_assign_rhs1 (gs)) == SSA_NAME);
  }
  
  
  /* Return true if GS is an assignment with a unary RHS, but the
     operator has no effect on the assigned value.  The logic is adapted
     from STRIP_NOPS.  This predicate is intended to be used in tuplifying
*************** gimple_assign_single_p (gimple gs)
*** 1929,1935 ****
  bool
  gimple_assign_unary_nop_p (gimple gs)
  {
!   return (gimple_code (gs) == GIMPLE_ASSIGN
            && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
                || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
            && gimple_assign_rhs1 (gs) != error_mark_node
--- 1912,1918 ----
  bool
  gimple_assign_unary_nop_p (gimple gs)
  {
!   return (is_gimple_assign (gs)
            && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs))
                || gimple_assign_rhs_code (gs) == NON_LVALUE_EXPR)
            && gimple_assign_rhs1 (gs) != error_mark_node
*************** is_gimple_min_lval (tree t)
*** 2950,2964 ****
    return (is_gimple_id (t) || TREE_CODE (t) == MEM_REF);
  }
  
- /* Return true if T is a typecast operation.  */
- 
- bool
- is_gimple_cast (tree t)
- {
-   return (CONVERT_EXPR_P (t)
-           || TREE_CODE (t) == FIX_TRUNC_EXPR);
- }
- 
  /* Return true if T is a valid function operand of a CALL_EXPR.  */
  
  bool
--- 2933,2938 ----
Index: gcc/gimple.h
===================================================================
*** gcc/gimple.h	(revision 167187)
--- gcc/gimple.h	(working copy)
*************** int gimple_call_arg_flags (const_gimple,
*** 869,875 ****
  void gimple_call_reset_alias_info (gimple);
  bool gimple_assign_copy_p (gimple);
  bool gimple_assign_ssa_name_copy_p (gimple);
- bool gimple_assign_single_p (gimple);
  bool gimple_assign_unary_nop_p (gimple);
  void gimple_set_bb (gimple, struct basic_block_def *);
  void gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *, tree);
--- 869,874 ----
*************** extern bool is_gimple_mem_rhs (tree);
*** 944,951 ****
  /* Returns true iff T is a valid if-statement condition.  */
  extern bool is_gimple_condexpr (tree);
  
- /* Returns true iff T is a type conversion.  */
- extern bool is_gimple_cast (tree);
  /* Returns true iff T is a variable that does not need to live in memory.  */
  extern bool is_gimple_non_addressable (tree t);
  
--- 943,948 ----
*************** gimple_assign_rhs_code (const_gimple gs)
*** 1904,1910 ****
    enum tree_code code;
    GIMPLE_CHECK (gs, GIMPLE_ASSIGN);
  
!   code = gimple_expr_code (gs);
    if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)
      code = TREE_CODE (gimple_assign_rhs1 (gs));
  
--- 1901,1910 ----
    enum tree_code code;
    GIMPLE_CHECK (gs, GIMPLE_ASSIGN);
  
!   code = (enum tree_code) gs->gsbase.subcode;
!   /* While we initially set subcode to the TREE_CODE of the rhs for
!      GIMPLE_SINGLE_RHS assigns we do not update that subcode to stay
!      in sync when we rewrite stmts into SSA form or do SSA propagations.  */
    if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)
      code = TREE_CODE (gimple_assign_rhs1 (gs));
  
*************** gimple_assign_rhs_class (const_gimple gs
*** 1933,1938 ****
--- 1933,1951 ----
    return get_gimple_rhs_class (gimple_assign_rhs_code (gs));
  }
  
+ /* Return true if GS is an assignment with a singleton RHS, i.e.,
+    there is no operator associated with the assignment itself.
+    Unlike gimple_assign_copy_p, this predicate returns true for
+    any RHS operand, including those that perform an operation
+    and do not have the semantics of a copy, such as COND_EXPR.  */
+ 
+ static inline bool
+ gimple_assign_single_p (gimple gs)
+ {
+   return (is_gimple_assign (gs)
+           && gimple_assign_rhs_class (gs) == GIMPLE_SINGLE_RHS);
+ }
+ 
  
  /* Return true if S is a type-cast assignment.  */
  
Index: gcc/gimple-fold.c
===================================================================
*** gcc/gimple-fold.c	(revision 167187)
--- gcc/gimple-fold.c	(working copy)
*************** gimple_fold_builtin (gimple stmt)
*** 1273,1279 ****
  	  /* If the result is not a valid gimple value, or not a cast
  	     of a valid gimple value, then we cannot use the result.  */
  	  if (is_gimple_val (new_val)
! 	      || (is_gimple_cast (new_val)
  		  && is_gimple_val (TREE_OPERAND (new_val, 0))))
  	    return new_val;
  	}
--- 1273,1279 ----
  	  /* If the result is not a valid gimple value, or not a cast
  	     of a valid gimple value, then we cannot use the result.  */
  	  if (is_gimple_val (new_val)
! 	      || (CONVERT_EXPR_P (new_val)
  		  && is_gimple_val (TREE_OPERAND (new_val, 0))))
  	    return new_val;
  	}
Index: gcc/ipa-type-escape.c
===================================================================
*** gcc/ipa-type-escape.c	(revision 167187)
--- gcc/ipa-type-escape.c	(working copy)
*************** look_for_casts (tree t)
*** 1236,1242 ****
  {
    unsigned int cast = 0;
  
!   if (is_gimple_cast (t) || TREE_CODE (t) == VIEW_CONVERT_EXPR)
      {
        tree castfromvar = TREE_OPERAND (t, 0);
        cast = cast | check_cast (TREE_TYPE (t), castfromvar);
--- 1236,1242 ----
  {
    unsigned int cast = 0;
  
!   if (CONVERT_EXPR_P (t) || TREE_CODE (t) == VIEW_CONVERT_EXPR)
      {
        tree castfromvar = TREE_OPERAND (t, 0);
        cast = cast | check_cast (TREE_TYPE (t), castfromvar);


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