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] Handle XOR in tree_expr_nonnegative_p


Many thanks to Hakan Hjort for pointing out another optimization
that I'd missed in my recent tweak to tree_expr_nonnegative_p.
The expression "A ^ B" is nonnegative, if A and B are nonnegative.

The following patch has been tested on i686-pc-linux-gnu with a
full "make bootstrap", all languages except treelang, and regression
tested with a top-level "make -k check" with no new failures.

Committed to mainline.


2004-03-25  Roger Sayle  <roger@eyesopen.com>

	* fold-const.c (tree_expr_nonnegative_p): Handle BIT_XOR_EXPR like
	BIT_IOR_EXPR; A^B is nonnegative when A and B are nonnegative.

	* gcc.dg/compare8.c: Add an additional test for XOR.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.358
diff -c -3 -p -r1.358 fold-const.c
*** fold-const.c	23 Mar 2004 19:11:35 -0000	1.358
--- fold-const.c	24 Mar 2004 23:34:56 -0000
*************** tree_expr_nonnegative_p (tree t)
*** 8721,8726 ****
--- 8721,8727 ----
        return tree_expr_nonnegative_p (TREE_OPERAND (t, 1))
  	     || tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
      case BIT_IOR_EXPR:
+     case BIT_XOR_EXPR:
        return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
  	     && tree_expr_nonnegative_p (TREE_OPERAND (t, 1));

Index: compare8.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/compare8.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 compare8.c
*** compare8.c	24 Mar 2004 00:19:06 -0000	1.1
--- compare8.c	25 Mar 2004 17:02:24 -0000
*************** g(unsigned short a1, unsigned short a2,
*** 13,15 ****
--- 13,21 ----
    return ((a1+a2)&5) > b ? 2 : 3;  /* { dg-bogus "signed and unsigned" } */
  }

+ int
+ h(unsigned short a1, unsigned short a2, unsigned int b)
+ {
+   return ((a1+a2)^5) > b ? 2 : 3;  /* { dg-bogus "signed and unsigned" } */
+ }
+


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]