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] fold-const.c: Reorganize fold - Part 15/n


Hi,

Attached is part 15 of my patch to reorganize fold.

This patch unrolls the "for" loop at the beginning of fold_binary.

I am planning to simplify calculation and uses of wins.  Before I do
that, I need to unroll this loop.

My plan is to fold and return a tree right away if wins = 1.
Currently, we wait until the last minute to take care of the case
where wins = 1.  (See binary: in fold_binary and jumps to the label).

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-03-06  Kazu Hirata  <kazu@cs.umass.edu>

	* fold-const.c (fold_binary): Remove handling of RANGE_EXPR.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.532
diff -C10 -d -p -r1.532 fold-const.c
*** fold-const.c	6 Mar 2005 20:14:16 -0000	1.532
--- fold-const.c	7 Mar 2005 00:08:48 -0000
*************** fold_binary (tree expr)
*** 7031,7097 ****
    tree t1 = NULL_TREE;
    tree tem;
    tree op0, op1;
    tree arg0 = NULL_TREE, arg1 = NULL_TREE;
    enum tree_code code = TREE_CODE (t);
    enum tree_code_class kind = TREE_CODE_CLASS (code);
  
    /* WINS will be nonzero when the switch is done
       if all operands are constant.  */
    int wins = 1;
-   int i;
  
    gcc_assert (IS_EXPR_CODE_CLASS (kind)
  	      && TREE_CODE_LENGTH (code) == 2);
  
!   op0 = TREE_OPERAND (t, 0);
!   op1 = TREE_OPERAND (t, 1);
!   for (i = 0; i < 2; i++)
      {
-       tree op = TREE_OPERAND (t, i);
        tree subop;
  
-       if (op == 0)
- 	continue;		/* Valid for CALL_EXPR, at least.  */
- 
        /* Strip any conversions that don't change the mode.  This is
  	 safe for every expression, except for a comparison expression
  	 because its signedness is derived from its operands.  So, in
  	 the latter case, only strip conversions that don't change the
  	 signedness.
  
  	 Note that this is done as an internal manipulation within the
  	 constant folder, in order to find the simplest representation
  	 of the arguments so that their form can be studied.  In any
  	 cases, the appropriate type conversions should be put back in
  	 the tree that will get out of the constant folder.  */
        if (kind == tcc_comparison)
! 	STRIP_SIGN_NOPS (op);
        else
! 	STRIP_NOPS (op);
  
!       if (TREE_CODE (op) == COMPLEX_CST)
! 	subop = TREE_REALPART (op);
        else
! 	subop = op;
  
        if (TREE_CODE (subop) != INTEGER_CST
  	  && TREE_CODE (subop) != REAL_CST)
  	/* Note that TREE_CONSTANT isn't enough:
  	   static var addresses are constant but we can't
  	   do arithmetic on them.  */
  	wins = 0;
  
!       if (i == 0)
! 	arg0 = op;
!       else if (i == 1)
! 	arg1 = op;
      }
  
    /* If this is a commutative operation, and ARG0 is a constant, move it
       to ARG1 to reduce the number of tests below.  */
    if (commutative_tree_code (code)
        && tree_swap_operands_p (arg0, arg1, true))
      return fold (build2 (code, type, op1, op0));
  
    /* Now WINS is set as described above,
       ARG0 is the first operand of EXPR,
--- 7031,7121 ----
    tree t1 = NULL_TREE;
    tree tem;
    tree op0, op1;
    tree arg0 = NULL_TREE, arg1 = NULL_TREE;
    enum tree_code code = TREE_CODE (t);
    enum tree_code_class kind = TREE_CODE_CLASS (code);
  
    /* WINS will be nonzero when the switch is done
       if all operands are constant.  */
    int wins = 1;
  
    gcc_assert (IS_EXPR_CODE_CLASS (kind)
  	      && TREE_CODE_LENGTH (code) == 2);
  
!   arg0 = op0 = TREE_OPERAND (t, 0);
!   arg1 = op1 = TREE_OPERAND (t, 1);
! 
!   if (arg0)
      {
        tree subop;
  
        /* Strip any conversions that don't change the mode.  This is
  	 safe for every expression, except for a comparison expression
  	 because its signedness is derived from its operands.  So, in
  	 the latter case, only strip conversions that don't change the
  	 signedness.
  
  	 Note that this is done as an internal manipulation within the
  	 constant folder, in order to find the simplest representation
  	 of the arguments so that their form can be studied.  In any
  	 cases, the appropriate type conversions should be put back in
  	 the tree that will get out of the constant folder.  */
        if (kind == tcc_comparison)
! 	STRIP_SIGN_NOPS (arg0);
        else
! 	STRIP_NOPS (arg0);
  
!       if (TREE_CODE (arg0) == COMPLEX_CST)
! 	subop = TREE_REALPART (arg0);
        else
! 	subop = arg0;
  
        if (TREE_CODE (subop) != INTEGER_CST
  	  && TREE_CODE (subop) != REAL_CST)
  	/* Note that TREE_CONSTANT isn't enough:
  	   static var addresses are constant but we can't
  	   do arithmetic on them.  */
  	wins = 0;
+     }
  
!   if (arg1)
!     {
!       tree subop;
! 
!       /* Strip any conversions that don't change the mode.  This is
! 	 safe for every expression, except for a comparison expression
! 	 because its signedness is derived from its operands.  So, in
! 	 the latter case, only strip conversions that don't change the
! 	 signedness.
! 
! 	 Note that this is done as an internal manipulation within the
! 	 constant folder, in order to find the simplest representation
! 	 of the arguments so that their form can be studied.  In any
! 	 cases, the appropriate type conversions should be put back in
! 	 the tree that will get out of the constant folder.  */
!       if (kind == tcc_comparison)
! 	STRIP_SIGN_NOPS (arg1);
!       else
! 	STRIP_NOPS (arg1);
! 
!       if (TREE_CODE (arg1) == COMPLEX_CST)
! 	subop = TREE_REALPART (arg1);
!       else
! 	subop = arg1;
! 
!       if (TREE_CODE (subop) != INTEGER_CST
! 	  && TREE_CODE (subop) != REAL_CST)
! 	/* Note that TREE_CONSTANT isn't enough:
! 	   static var addresses are constant but we can't
! 	   do arithmetic on them.  */
! 	wins = 0;
      }
  
    /* If this is a commutative operation, and ARG0 is a constant, move it
       to ARG1 to reduce the number of tests below.  */
    if (commutative_tree_code (code)
        && tree_swap_operands_p (arg0, arg1, true))
      return fold (build2 (code, type, op1, op0));
  
    /* Now WINS is set as described above,
       ARG0 is the first operand of EXPR,


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