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]

[Committed] Factor "fold_not_const" into its own function


The following minor clean-up to fold-const.c factors some duplicated
code in "fold" and "nondestructive_fold_unary_to_constant" into its
own subroutine, fold_not_const.  This follows the conventions used
by fold_negate_const and fold_abs_const.

In addition I wrap a long line, and tweak the condition in fold's
ABS_EXPR case; The variable "wins" should be identical to whether
the unary operator's single operands is either a real or integer
constant.  These are also the only cases that fold_abs_const handles.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with
a top-level "make -k check" with no new failures.  There should be
no functional changes.

Committed to mainline CVS.


2004-06-09  Roger Sayle  <roger@eyesopen.com>

	* fold-const.c (fold_not_const): New function.
	(fold) <ABS_EXPR>: Don't bother testing wins.
	(fold) <BIT_NOT_EXPR>: Call fold_not_const.
	(nondestructive_fold_unary_to_constant) <BIT_NOT_EXPR>: Likewise.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.388
diff -c -3 -p -r1.388 fold-const.c
*** fold-const.c	7 Jun 2004 20:50:09 -0000	1.388
--- fold-const.c	9 Jun 2004 21:31:51 -0000
*************** static bool tree_swap_operands_p (tree,
*** 136,143 ****

  static tree fold_negate_const (tree, tree);
  static tree fold_abs_const (tree, tree);
  static tree fold_relational_const (enum tree_code, tree, tree, tree);
! static tree fold_relational_hi_lo (enum tree_code *, const tree, tree *, tree *);

  /* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring
     overflow.  Suppose A, B and SUM have the same respective signs as A1, B1,
--- 136,145 ----

  static tree fold_negate_const (tree, tree);
  static tree fold_abs_const (tree, tree);
+ static tree fold_not_const (tree, tree);
  static tree fold_relational_const (enum tree_code, tree, tree, tree);
! static tree fold_relational_hi_lo (enum tree_code *, const tree,
!                                    tree *, tree *);

  /* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring
     overflow.  Suppose A, B and SUM have the same respective signs as A1, B1,
*************** fold (tree expr)
*** 6016,6023 ****
        return t;

      case ABS_EXPR:
!       if (wins
! 	  && (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST))
  	return fold_abs_const (arg0, type);
        else if (TREE_CODE (arg0) == NEGATE_EXPR)
  	return fold (build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0)));
--- 6018,6024 ----
        return t;

      case ABS_EXPR:
!       if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST)
  	return fold_abs_const (arg0, type);
        else if (TREE_CODE (arg0) == NEGATE_EXPR)
  	return fold (build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0)));
*************** fold (tree expr)
*** 6056,6071 ****
        return t;

      case BIT_NOT_EXPR:
!       if (wins)
! 	{
! 	  tem = build_int_2 (~ TREE_INT_CST_LOW (arg0),
! 			     ~ TREE_INT_CST_HIGH (arg0));
! 	  TREE_TYPE (tem) = type;
! 	  force_fit_type (tem, 0);
! 	  TREE_OVERFLOW (tem) = TREE_OVERFLOW (arg0);
! 	  TREE_CONSTANT_OVERFLOW (tem) = TREE_CONSTANT_OVERFLOW (arg0);
! 	  return tem;
! 	}
        else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
  	return TREE_OPERAND (arg0, 0);
        return t;
--- 6057,6064 ----
        return t;

      case BIT_NOT_EXPR:
!       if (TREE_CODE (arg0) == INTEGER_CST)
!         return fold_not_const (arg0, type);
        else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
  	return TREE_OPERAND (arg0, 0);
        return t;
*************** tree
*** 9695,9702 ****
  nondestructive_fold_unary_to_constant (enum tree_code code, tree type,
  				       tree op0)
  {
-   tree t;
-
    /* Make sure we have a suitable constant argument.  */
    if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR)
      {
--- 9688,9693 ----
*************** nondestructive_fold_unary_to_constant (e
*** 9734,9748 ****
  	return NULL_TREE;

      case BIT_NOT_EXPR:
!       if (TREE_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST)
! 	{
! 	  t = build_int_2 (~ TREE_INT_CST_LOW (op0), ~ TREE_INT_CST_HIGH (op0));
! 	  TREE_TYPE (t) = type;
! 	  force_fit_type (t, 0);
! 	  TREE_OVERFLOW (t) = TREE_OVERFLOW (op0);
! 	  TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (op0);
! 	  return t;
! 	}
        else
  	return NULL_TREE;

--- 9725,9732 ----
  	return NULL_TREE;

      case BIT_NOT_EXPR:
!       if (TREE_CODE (op0) == INTEGER_CST)
! 	return fold_not_const (op0, type);
        else
  	return NULL_TREE;

*************** fold_abs_const (tree arg0, tree type)
*** 9908,9913 ****
--- 9892,9922 ----
    return t;
  }

+ /* Return the tree for not (ARG0) when ARG0 is known to be an integer
+    constant.  TYPE is the type of the result.  */
+
+ static tree
+ fold_not_const (tree arg0, tree type)
+ {
+   tree t = NULL_TREE;
+
+   if (TREE_CODE (arg0) == INTEGER_CST)
+     {
+       t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
+ 		       ~ TREE_INT_CST_HIGH (arg0));
+       TREE_TYPE (t) = type;
+       force_fit_type (t, 0);
+       TREE_OVERFLOW (t) = TREE_OVERFLOW (arg0);
+       TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (arg0);
+     }
+ #ifdef ENABLE_CHECKING
+   else
+     abort ();
+ #endif
+
+   return t;
+ }
+
  /* Given CODE, a relational operator, the target type, TYPE and two
     constant operands OP0 and OP1, return the result of the
     relational operation.  If the result is not a compile time

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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