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] PR 19944


 Hi,

  It seems my patch to fold-const.c has been accidentally reverted.  This
patch readds the folding and uses the suggestions Roger had.  I have
bootstrapped and regtested the revised folding on sparc64-linux.

-- 
Thanks,
Jim

http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.509
diff -u -p -r1.509 fold-const.c
--- fold-const.c	13 Feb 2005 17:10:45 -0000	1.509
+++ fold-const.c	14 Feb 2005 00:32:06 -0000
@@ -8973,6 +8973,26 @@ fold (tree expr)
 			     build2 (LE_EXPR, type,
 				     TREE_OPERAND (arg0, 0), arg1)));
 
+      /* Convert ABS_EXPR<x> >= 0 to true.  */
+      else if (code == GE_EXPR
+	       && tree_expr_nonnegative_p (arg0)
+	       && (integer_zerop (arg1)
+		   || (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
+                       && real_zerop (arg1))))
+	return omit_one_operand (type, integer_one_node, arg0);
+
+      /* Convert ABS_EXPR<x> < 0 to false.  */
+      else if (code == LT_EXPR
+	       && tree_expr_nonnegative_p (arg0)
+	       && (integer_zerop (arg1) || real_zerop (arg1)))
+	return omit_one_operand (type, integer_zero_node, arg0);
+
+      /* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0.  */
+      else if ((code == EQ_EXPR || code == NE_EXPR)
+	       && TREE_CODE (arg0) == ABS_EXPR
+	       && (integer_zerop (arg1) || real_zerop (arg1)))
+	return fold (build2 (code, type, TREE_OPERAND (arg0, 0), arg1));
+
       /* If this is an EQ or NE comparison with zero and ARG0 is
 	 (1 << foo) & bar, convert it to (bar >> foo) & 1.  Both require
 	 two operations, but the latter can be done in one less insn
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 2.7465
diff -u -p -r2.7465 ChangeLog
--- ChangeLog	13 Feb 2005 21:31:16 -0000	2.7465
+++ ChangeLog	14 Feb 2005 00:32:07 -0000
@@ -1,3 +1,8 @@
+2005-02-13  James A. Morrison  <phython@gcc.gnu.org>
+
+	PR tree-optimization/19944
+	* fold-const.c (fold): Re-add ABS_EXPR folding.
+
 2005-02-13  David Edelsohn  <edelsohn@gnu.org>
 
 	PR target/19019

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