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] Don't handle TRUTH_NOT_EXPR in fold_single_bit_test


The following clean-up is an independent piece of a larger patch to
address a performance regression on AVR, whose solution involves
making fold_single_bit_test recursive.  Whilst investigating I noticed
that the handling of TRUTH_NOT_EXPR on the critical path can never
occur in practice; fold_single_bit_test concerns itself with either
EQ_EXPR or NE_EXPR of an integer type against zero, and these should
also ways be inverted/folded by invert_truthvalue.  i.e. the function
fold_single_bit_test should never find anything to do under a
TRUTH_NOT_EXPR (confirmed by adding an abort and then bootstrapping
and regression testing).  This clean-up simply deletes this unreachable
code, and should have a very minor performance benefit.

The following patch was 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.

Committed to mainline CVS.



2005-01-04  Roger Sayle  <roger@eyesopen.com>

	* fold-const.c (fold_single_bit_test): Delete unreachable handling
	of TRUTH_NOT_EXPR.
	(fold): Don't call fold_single_bit_test with a TRUTH_NOT_EXPR, as
	all the cases handled by it are inverted by invert_truthvalue.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.488
diff -c -3 -p -r1.488 fold-const.c
*** fold-const.c	28 Dec 2004 15:56:51 -0000	1.488
--- fold-const.c	2 Jan 2005 17:54:39 -0000
*************** tree
*** 5811,5832 ****
  fold_single_bit_test (enum tree_code code, tree arg0, tree arg1,
  		      tree result_type)
  {
-   /* If this is a TRUTH_NOT_EXPR, it may have a single bit test inside
-      operand 0.  */
-   if (code == TRUTH_NOT_EXPR)
-     {
-       code = TREE_CODE (arg0);
-       if (code != NE_EXPR && code != EQ_EXPR)
- 	return NULL_TREE;
-
-       /* Extract the arguments of the EQ/NE.  */
-       arg1 = TREE_OPERAND (arg0, 1);
-       arg0 = TREE_OPERAND (arg0, 0);
-
-       /* This requires us to invert the code.  */
-       code = (code == EQ_EXPR ? NE_EXPR : EQ_EXPR);
-     }
-
    /* If this is testing a single bit, we can optimize the test.  */
    if ((code == NE_EXPR || code == EQ_EXPR)
        && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
--- 5811,5816 ----
*************** fold (tree expr)
*** 8025,8036 ****
        tem = invert_truthvalue (arg0);
        /* Avoid infinite recursion.  */
        if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
! 	{
! 	  tem = fold_single_bit_test (code, arg0, arg1, type);
! 	  if (tem)
! 	    return tem;
! 	  return t;
! 	}
        return fold_convert (type, tem);

      case TRUTH_ANDIF_EXPR:
--- 8009,8015 ----
        tem = invert_truthvalue (arg0);
        /* Avoid infinite recursion.  */
        if (TREE_CODE (tem) == TRUTH_NOT_EXPR)
! 	return t;
        return fold_convert (type, tem);

      case TRUTH_ANDIF_EXPR:


Roger
--


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