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]

Re: Add overflow infinity handling to VRP


Ian Lance Taylor wrote on 01/02/07 19:55:

This patch changes VRP by introducing a notion of an overflow
infinity.  The overflow infinity value is used when an operation
overflows.  The positive (negative) overflow infinity for a type is
simply a copy of the TYPE_MAX_VALUE (TYPE_MIN_VALUE) for the type.  We
use a small hash table to pick up the overflow value.

I like the idea.  Thanks for tackling this.  I know you have another
version of this patch in testing, so the observations I have here may
be moot.

One suggestion regarding the hash table for infinities.  What about a
dense array indexed on TYPE_UID?  In vrp_initialize we could discover
the smallest TYPE_UID used in the SSA table and use that as the 0th
slot.  I don't know how dense TYPE_UIDs are, so this may be
nonsensical.

We seem to be accessing this hash table quite a bit.  Any performance
problems due to that?

@@ -454,6 +623,20 @@ static inline int
 operand_less_p (tree val, tree val2)
 {
   tree tcmp;
+
+  if (is_overflow_infinity (val) || is_overflow_infinity (val2))
+    {
+      if (is_negative_overflow_infinity (val2))
+	return 0;
+      else if (is_negative_overflow_infinity (val))
+	return 1;
+      else if (is_positive_overflow_infinity (val))
+	return 0;
+      else if (is_positive_overflow_infinity (val2))
+	return 1;
+      gcc_unreachable ();
+    }
+
Shouldn't we handle the case where *both* VAL and VAL2 have overflowed
in whichever direction?  Also, if either VAL or VAL2 have overflowed,
shouldn't we always return -2?  This is handling the cases where
-fwrapv has been used, right?

I think I've gotten confused here.


   /* LT is folded faster than GE and others.  Inline the common case.  */
   if (TREE_CODE (val) == INTEGER_CST && TREE_CODE (val2) == INTEGER_CST)
     {
@@ -517,9 +700,15 @@ compare_values (tree val1, tree val2)
 	  c1 = TREE_OPERAND (val1, 1);
 	  if (tree_int_cst_sgn (c1) == -1)
 	    {
-	      c1 = fold_unary_to_constant (NEGATE_EXPR, TREE_TYPE (c1), c1);
-	      if (!c1)
-		return -2;
+	      if (is_negative_overflow_infinity (c1))
+		c2 = positive_infinity (TREE_TYPE (c1));

Don't you mean 'c1 = positive_infinity' here?


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