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] Some ivopts improvements


Hello,

this patch contains two improvements related to ivopts.

1) for loops of type

   p = &a[0];
   q = &a[10];
   while (...)
     *p++ = *q++;

   we currently do not recognize that the ivs p and q differ by constant
   only.  This type of code may occur due to users hand-optimizing the
   code, but it is also produced by the new prefetching pass I am
   working on now.

   Fixed by propagating simple operations to bases of the ivs.

2) number_of_iterations_cond uses tree_expr_nonnegative_p to detect
   whether we are not dealing with paradoxical loops.  This test fails 
   when the control variable is unsigned, since then
   tree_expr_nonnegative_p is always true.

   Fixed by using tree_int_cst_sign_bit instead.

Bootstrapped & regtested on i686.

Zdenek

	* tree-ssa-loop-ivopts.c (find_bivs, find_givs_in_stmt_scev): Apply
	expand_simple_operations to bases of the ivs.
	(tree_int_cst_sign_bit): Export.
	* tree-flow.h (expand_simple_operations): Declare.
	* tree-ssa-loop-niter.c (number_of_iterations_cond): Use
	tree_int_cst_sign_bit.
	(expand_simple_operations): Export.
	* tree.h (tree_int_cst_sign_bit): Declare.

Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
retrieving revision 2.69
diff -c -3 -p -r2.69 tree-ssa-loop-ivopts.c
*** tree-ssa-loop-ivopts.c	4 May 2005 13:57:40 -0000	2.69
--- tree-ssa-loop-ivopts.c	16 May 2005 14:04:19 -0000
*************** find_bivs (struct ivopts_data *data)
*** 992,997 ****
--- 992,998 ----
  	continue;
  
        base = PHI_ARG_DEF_FROM_EDGE (phi, loop_preheader_edge (loop));
+       base = expand_simple_operations (base);
        if (contains_abnormal_ssa_name_p (base)
  	  || contains_abnormal_ssa_name_p (step))
  	continue;
*************** find_givs_in_stmt_scev (struct ivopts_da
*** 1062,1067 ****
--- 1063,1069 ----
  
    if (!simple_iv (loop, stmt, TREE_OPERAND (stmt, 1), base, step, true))
      return false;
+   *base = expand_simple_operations (*base);
  
    if (contains_abnormal_ssa_name_p (*base)
        || contains_abnormal_ssa_name_p (*step))
*************** var_at_stmt (struct loop *loop, struct i
*** 2536,2542 ****
  /* Return the most significant (sign) bit of T.  Similar to tree_int_cst_msb,
     but the bit is determined from TYPE_PRECISION, not MODE_BITSIZE.  */
  
! static int
  tree_int_cst_sign_bit (tree t)
  {
    unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;
--- 2538,2544 ----
  /* Return the most significant (sign) bit of T.  Similar to tree_int_cst_msb,
     but the bit is determined from TYPE_PRECISION, not MODE_BITSIZE.  */
  
! int
  tree_int_cst_sign_bit (tree t)
  {
    unsigned bitno = TYPE_PRECISION (TREE_TYPE (t)) - 1;

Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-flow.h,v
retrieving revision 2.104
diff -c -3 -p -r2.104 tree-flow.h
*** tree-flow.h	12 May 2005 22:32:16 -0000	2.104
--- tree-flow.h	16 May 2005 14:04:19 -0000
*************** bool tree_duplicate_loop_to_header_edge 
*** 721,728 ****
--- 723,731 ----
  					 unsigned int, sbitmap,
  					 edge, edge *,
  					 unsigned int *, int);
  struct loop *tree_ssa_loop_version (struct loops *, struct loop *, tree,
  				    basic_block *);
+ tree expand_simple_operations (tree);
  
  /* In tree-ssa-loop-im.c  */
  /* The possibilities of statement movement.  */
Index: tree-ssa-loop-niter.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-niter.c,v
retrieving revision 2.26
diff -c -3 -p -r2.26 tree-ssa-loop-niter.c
*** tree-ssa-loop-niter.c	3 May 2005 12:19:46 -0000	2.26
--- tree-ssa-loop-niter.c	16 May 2005 14:04:19 -0000
*************** number_of_iterations_cond (tree type, tr
*** 189,198 ****
    /* Ignore loops of while (i-- < 10) type.  */
    if (code != NE_EXPR)
      {
!       if (step0 && !tree_expr_nonnegative_p (step0))
  	return;
  
!       if (!zero_p (step1) && tree_expr_nonnegative_p (step1))
  	return;
      }
  
--- 189,198 ----
    /* Ignore loops of while (i-- < 10) type.  */
    if (code != NE_EXPR)
      {
!       if (step0 && tree_int_cst_sign_bit (step0))
  	return;
  
!       if (!zero_p (step1) && !tree_int_cst_sign_bit (step1))
  	return;
      }
  
*************** number_of_iterations_cond (tree type, tr
*** 366,372 ****
        if (!zero_p (step1))
    	step0 = fold_unary_to_constant (NEGATE_EXPR, type, step1);
        step1 = NULL_TREE;
!       if (!tree_expr_nonnegative_p (fold_convert (signed_niter_type, step0)))
  	{
  	  step0 = fold_unary_to_constant (NEGATE_EXPR, type, step0);
  	  base1 = fold_build1 (NEGATE_EXPR, type, base1);
--- 366,372 ----
        if (!zero_p (step1))
    	step0 = fold_unary_to_constant (NEGATE_EXPR, type, step1);
        step1 = NULL_TREE;
!       if (tree_int_cst_sign_bit (fold_convert (signed_niter_type, step0)))
  	{
  	  step0 = fold_unary_to_constant (NEGATE_EXPR, type, step0);
  	  base1 = fold_build1 (NEGATE_EXPR, type, base1);
*************** simplify_replace_tree (tree expr, tree o
*** 627,633 ****
  /* Expand definitions of ssa names in EXPR as long as they are simple
     enough, and return the new expression.  */
  
! static tree
  expand_simple_operations (tree expr)
  {
    unsigned i, n;
--- 627,633 ----
  /* Expand definitions of ssa names in EXPR as long as they are simple
     enough, and return the new expression.  */
  
! tree
  expand_simple_operations (tree expr)
  {
    unsigned i, n;
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.727
diff -c -3 -p -r1.727 tree.h
*** tree.h	11 May 2005 16:25:30 -0000	1.727
--- tree.h	16 May 2005 14:04:20 -0000
*************** extern int host_integerp (tree, int);
*** 2953,2958 ****
--- 2953,2959 ----
  extern HOST_WIDE_INT tree_low_cst (tree, int);
  extern int tree_int_cst_msb (tree);
  extern int tree_int_cst_sgn (tree);
+ extern int tree_int_cst_sign_bit (tree);
  extern int tree_expr_nonnegative_p (tree);
  extern bool may_negate_without_overflow_p (tree);
  extern tree get_inner_array_type (tree);


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