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] Fix pr23046


 Hi,

  This is the fold patch that was refered to recently on the GCC list for
this bug.  It allows fold to fold X > TYPE_MAX_VALUE and X < TYPE_MIN_VALUE to
0.  This patch has been bootstrapped and regtested on ia64-linux with all
languages except Ada with no new regressions.  Ok for mainline?

-- 
Thanks,
Jim

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

2005-08-05  James A. Morrison  <phython@gcc.gnu.org>

	PR middle-end/23046
	* fold-const.c (fold_binary): Return 0 for X > TYPE_MAX_VALUE or
	X < TYPE_MIN_VALUE.

Index: fold-const.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.611
diff -u -p -r1.611 fold-const.c
--- fold-const.c	26 Jul 2005 13:53:49 -0000	1.611
+++ fold-const.c	6 Aug 2005 05:43:28 -0000
@@ -9169,6 +9169,15 @@ fold_binary (enum tree_code code, tree t
 	    }
 	}
 
+      /* Comparisons with the highest or lowest value of a type.  */
+      if (TREE_CODE (arg1) == INTEGER_CST && INTEGRAL_TYPE_P (TREE_TYPE (arg0))
+	  && ((code == GT_EXPR
+	       && tree_int_cst_equal (arg1, TYPE_MAX_VALUE (TREE_TYPE (arg0))))
+              || (code == LT_EXPR
+	          && tree_int_cst_equal (arg1,
+					 TYPE_MIN_VALUE (TREE_TYPE (arg0))))))
+	return omit_one_operand (type, integer_zero_node, arg0);
+
       /* Comparisons with the highest or lowest possible integer of
 	 the specified size will have known values.  */
       {
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-useless -ftree-vrp" } */

/* This used to ICE in VRP because we didn't optimize X > TYPE_MAX (X).  */

enum eumtype { ENUM1, ENUM2 };
void g(const eumtype kind );
void f(long i);
void g(const eumtype kind)
{
  if ((kind != ENUM1) && (kind != ENUM2))
    f(kind);
}
/* { dg-final { scan-tree-dump-times "if" 0 "useless" } } */
/* { dg-final { cleanup-tree-dump "useless" } } */

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