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] associative minus and shift?


Someone must have been thinking of a different definition of
these operators than the one with which I am familiar.  Hmph.

I expect this was hidden by the non-gimple code that was being
generated in the building and folding of expressions here.
Jeff patched this with 

        * tree-ssa-phiopt.c (conditional_replacement): Do not create
        non-gimple code.
        * tree-ssa-dom.c (simplify_rhs_and_lookup_avail_expr): Likewise.

after the merge started, but he did it in a way that effectively
disabled optimization here at all, because the test will always
fail.

Fix that, and handle minus specially since plus-minus arithmetic
is particularly important.


r~



        * tree.c (associative_tree_code): Remove MINUS_EXPR, LSHIFT_EXPR,
        RSHIFT_EXPR.
        * tree-ssa-dom.c (simplify_rhs_and_lookup_avail_expr): Use 
        is_gimple_min_invariant and is_gimple_var.  Handle minus_expr
        specially.

Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.263.2.81
diff -c -p -d -r1.263.2.81 tree.c
*** tree.c	24 Feb 2004 09:25:31 -0000	1.263.2.81
--- tree.c	2 Mar 2004 08:48:32 -0000
*************** associative_tree_code (enum tree_code co
*** 3641,3650 ****
      case BIT_AND_EXPR:
      case BIT_XOR_EXPR:
      case PLUS_EXPR:
-     case MINUS_EXPR:
      case MULT_EXPR:
-     case LSHIFT_EXPR:
-     case RSHIFT_EXPR:
      case MIN_EXPR:
      case MAX_EXPR:
        return true;
--- 3655,3661 ----
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.144
diff -c -p -d -r1.1.2.144 tree-ssa-dom.c
*** tree-ssa-dom.c	1 Mar 2004 14:41:03 -0000	1.1.2.144
--- tree-ssa-dom.c	2 Mar 2004 08:48:32 -0000
*************** simplify_rhs_and_lookup_avail_expr (stru
*** 1654,1663 ****
    /* If we have z = (x OP C1), see if we earlier had x = y OP C2.
       If OP is associative, create and fold (y OP C2) OP C1 which
       should result in (y OP C3), use that as the RHS for the
!      assignment.  */
!   if (associative_tree_code (rhs_code)
        && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
!       && TREE_CONSTANT (TREE_OPERAND (rhs, 1)))
      {
        tree rhs_def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
  
--- 1654,1663 ----
    /* If we have z = (x OP C1), see if we earlier had x = y OP C2.
       If OP is associative, create and fold (y OP C2) OP C1 which
       should result in (y OP C3), use that as the RHS for the
!      assignment.  Add minus to this, as we handle it specially below.  */
!   if ((associative_tree_code (rhs_code) || rhs_code == MINUS_EXPR)
        && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
!       && is_gimple_min_invariant (TREE_OPERAND (rhs, 1)))
      {
        tree rhs_def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
  
*************** simplify_rhs_and_lookup_avail_expr (stru
*** 1676,1689 ****
  
  	      if (TREE_CODE (def_stmt_op0) == SSA_NAME
  		  && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def_stmt_op0)
! 		  && TREE_CONSTANT (def_stmt_op1))
  		{
  		  tree outer_const = TREE_OPERAND (rhs, 1);
  		  tree type = TREE_TYPE (TREE_OPERAND (stmt, 0));
  		  tree t;
  
! 		  /* Build and fold (Y OP C2) OP C1.  */
! 		  t = build (rhs_code, type, rhs_def_rhs, outer_const);
  		  t = local_fold (t);
  
  		  /* If the result is a suitable looking gimple expression,
--- 1676,1705 ----
  
  	      if (TREE_CODE (def_stmt_op0) == SSA_NAME
  		  && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def_stmt_op0)
! 		  && is_gimple_min_invariant (def_stmt_op1))
  		{
  		  tree outer_const = TREE_OPERAND (rhs, 1);
  		  tree type = TREE_TYPE (TREE_OPERAND (stmt, 0));
  		  tree t;
  
! 		  /* Ho hum.  So fold will only operate on the outermost
! 		     thingy that we give it, so we have to build the new
! 		     expression in two pieces.  This requires that we handle
! 		     combinations of plus and minus.  */
! 		  if (rhs_def_code != rhs_code)
! 		    {
! 		      if (rhs_def_code == MINUS_EXPR)
! 		        t = build (MINUS_EXPR, type, outer_const, def_stmt_op1);
! 		      else
! 		        t = build (MINUS_EXPR, type, def_stmt_op1, outer_const);
! 		      rhs_code = PLUS_EXPR;
! 		    }
! 		  else if (rhs_def_code == MINUS_EXPR)
! 		    t = build (PLUS_EXPR, type, def_stmt_op1, outer_const);
! 		  else
! 		    t = build (rhs_def_code, type, def_stmt_op1, outer_const);
! 		  t = local_fold (t);
! 		  t = build (rhs_code, type, def_stmt_op0, t);
  		  t = local_fold (t);
  
  		  /* If the result is a suitable looking gimple expression,
*************** simplify_rhs_and_lookup_avail_expr (stru
*** 1694,1701 ****
  		      || ((TREE_CODE_CLASS (TREE_CODE (t)) == '2'
  			   || TREE_CODE_CLASS (TREE_CODE (t)) == '<')
  			  && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
! 			  && (TREE_CODE (TREE_OPERAND (t, 1)) == SSA_NAME
! 			      || TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (t, 1))) == 'c')))
  		    result = update_rhs_and_lookup_avail_expr
  		      (stmt, t, &bd->avail_exprs, ann, insert);
  		}
--- 1710,1716 ----
  		      || ((TREE_CODE_CLASS (TREE_CODE (t)) == '2'
  			   || TREE_CODE_CLASS (TREE_CODE (t)) == '<')
  			  && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
! 			  && is_gimple_val (TREE_OPERAND (t, 1))))
  		    result = update_rhs_and_lookup_avail_expr
  		      (stmt, t, &bd->avail_exprs, ann, insert);
  		}


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