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] Deal with larger anti-ranages in compare_range_with_value


 Hi,

  This patch allows us to fold a_1 == C into false if C is in the anti-range
for a_1.  Bootstrapped and regtested on ia64-linux.  Ok for mainline?

-- 
Thanks,
Jim

http://www.csclub.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
2005-07-27  James A. MOrrison  <phython@gcc.gnu.org>

	* tree-vrp.c (compare_range_with_value): Return false for
	~[VAL_1, VAL_2] == VAL if VAL_1 <= VAL <= VAL_2.

Index: tree-vrp.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.42
diff -u -p -r2.42 tree-vrp.c
--- tree-vrp.c	20 Jul 2005 20:26:00 -0000	2.42
+++ tree-vrp.c	27 Jul 2005 14:40:26 -0000
@@ -1695,6 +1743,9 @@ compare_range_with_value (enum tree_code
   /* Anti-ranges need to be handled separately.  */
   if (vr->type == VR_ANTI_RANGE)
     {
+      int min_comp = compare_values (vr->min, val);
+      int max_comp = compare_values (vr->max, val);
+
       /* For anti-ranges, the only predicates that we can compute at
 	 compile time are equality and inequality.  */
       if (comp == GT_EXPR
@@ -1703,10 +1754,15 @@ compare_range_with_value (enum tree_code
 	  || comp == LE_EXPR)
 	return NULL_TREE;
 
-      /* ~[VAL, VAL] == VAL is always false.  */
-      if (compare_values (vr->min, val) == 0
-	  && compare_values (vr->max, val) == 0)
-	return (comp == NE_EXPR) ? boolean_true_node : boolean_false_node;
+      /* ~[VAL, VAL] != VAL is true.  */
+      if (comp == NE_EXPR && min_comp == 0 && max_comp == 0)
+	return boolean_true_node;
+
+      /* ~[VAL_1, VAL_2] == VAL is false if VAL_1 <= VAL <= VAL_2.  */
+      if (comp == EQ_EXPR
+	  && (min_comp == 0 || min_comp == -1)
+	  && (max_comp == 0 || max_comp == 1))
+	return boolean_false_node;
 
       return NULL_TREE;
     }
testsuite:
        * gcc.dg/tree-ssa/vrp18.c: New test.
        * gcc.dg/tree-ssa-vrp19.c: New test.

/* { dg-do compile } */
/* { dg-options "-fwrapv -O1 -ftree-vrp -fdump-tree-vrp" } */

extern void abort ();
extern void exit (int);

int f (int a) {
	if (a != 0) {
		a = a > 0 ? a : -a;
		if (a == 0)
		  return 1;
		return 0;
	}
	return 0;
}

/* { dg-final { scan-tree-dump "Folding predicate a_. == 0 to 0" "vrp" } } */
/* { dg-final { cleanup-tree-dump "vrp" } } */
/* { dg-do compile } */
/* { dg-options "-fwrapv -O1 -ftree-vrp -fdump-tree-vrp" } */

#include <limits.h>
extern void abort ();
extern void exit (int);

int f (int a) {
	if (a != INT_MIN) {
		a = a > 0 ? a : -a;
		if (a < 0)
		  return 1;
		else if (a >= 0)
		  return 0;
	}
	return 0;
}

/* { dg-final { scan-tree-dump-times "if \\\(.*< 0" 0 "vrp" } } */
/* { dg-final { scan-tree-dump-times "if \\\(.* >= 0" 0 "vrp" } } */

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