As requested this adds predicates to check whether the lhs of
a assign or call is a store and whether rhs1 of an assignment
is a load.  It uses this in place of the existing, slightly
bogus, check in the stmt estimate code.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2012-10-30  Richard Biener  <rguent...@suse.de>

        * gimple.h (gimple_store_p): New predicate.
        (gimple_assign_load_p): Likewise.
        * tree-inline.c (estimate_num_insns): Use it.

Index: gcc/gimple.h
===================================================================
*** gcc/gimple.h        (revision 192984)
--- gcc/gimple.h        (working copy)
*************** gimple_assign_single_p (gimple gs)
*** 2041,2046 ****
--- 2041,2071 ----
            && gimple_assign_rhs_class (gs) == GIMPLE_SINGLE_RHS);
  }
  
+ /* Return true if GS performs a store to its lhs.  */
+ 
+ static inline bool
+ gimple_store_p (gimple gs)
+ {
+   tree lhs = gimple_get_lhs (gs);
+   return lhs && !is_gimple_reg (lhs);
+ }
+ 
+ /* Return true if GS is an assignment that loads from its rhs1.  */
+ 
+ static inline bool
+ gimple_assign_load_p (gimple gs)
+ {
+   tree rhs;
+   if (!gimple_assign_single_p (gs))
+     return false;
+   rhs = gimple_assign_rhs1 (gs);
+   if (TREE_CODE (rhs) == WITH_SIZE_EXPR)
+     return true;
+   rhs = get_base_address (rhs);
+   return (DECL_P (rhs)
+         || TREE_CODE (rhs) == MEM_REF || TREE_CODE (rhs) == TARGET_MEM_REF);
+ }
+ 
  
  /* Return true if S is a type-cast assignment.  */
  
Index: gcc/tree-inline.c
===================================================================
*** gcc/tree-inline.c   (revision 192984)
--- gcc/tree-inline.c   (working copy)
*************** estimate_num_insns (gimple stmt, eni_wei
*** 3512,3523 ****
        lhs = gimple_assign_lhs (stmt);
        rhs = gimple_assign_rhs1 (stmt);
  
!       if (is_gimple_reg (lhs))
!       cost = 0;
!       else
!       cost = estimate_move_cost (TREE_TYPE (lhs));
  
!       if (!is_gimple_reg (rhs) && !is_gimple_min_invariant (rhs))
        cost += estimate_move_cost (TREE_TYPE (rhs));
  
        cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights,
--- 3512,3523 ----
        lhs = gimple_assign_lhs (stmt);
        rhs = gimple_assign_rhs1 (stmt);
  
!       cost = 0;
  
!       /* Account for the cost of moving to / from memory.  */
!       if (gimple_store_p (stmt))
!       cost += estimate_move_cost (TREE_TYPE (lhs));
!       if (gimple_assign_load_p (stmt))
        cost += estimate_move_cost (TREE_TYPE (rhs));
  
        cost += estimate_operator_cost (gimple_assign_rhs_code (stmt), weights,

Reply via email to