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: Some VRP improvements


> - Changed the extraction of ranges from binary and unary
>   expressions to not overflow ranges when -fno-wrapv is used.  In
>   those cases, operations never cause wrap around, so -INF and
>   +INF are always preserved.  Also fixed the evaluation of
>   ABS_EXPR, MINUS_EXPR and *_DIV_EXPR, which were wrongly
>   computed.

+  /* If MAX overflowed, then the result depends on whether we are
+     using wrapping arithmetic or not.  */
+  if (TREE_OVERFLOW (max))
+    {
+      /* If we are using wrapping arithmetic, set the result to
+	 VARYING.  */
+      if (flag_wrapv)
+	{
+	  set_value_range_to_varying (vr);
+	  return;
+	}
+
+      /* Otherwise, set MAX to +INF.  */
+      max = TYPE_MAX_VALUE (TREE_TYPE (expr));
+    }
+
+  /* If MIN overflowed, then the result depends on whether we are
+     using wrapping arithmetic or not.  */
+  if (TREE_OVERFLOW (min))
+    {
+      /* If we are using wrapping arithmetic, set the result to
+	 VARYING.  */
+      if (flag_wrapv)
+	{
+	  set_value_range_to_varying (vr);
+	  return;
+	}
+
+      /* Otherwise, set MIN to -INF.  */
+      min = TYPE_MIN_VALUE (TREE_TYPE (expr));
+    }

That doesn't work correctly when a MULT_EXPR swaps the min and the max 
(extract_bit_field is miscompiled on SPARC if HOST_BITS_PER_WIDE_INT == 32 
because of that, preprocessed file attached):

  i.56_172 = (int) i_24;
  D.12872_173 = i.56_172 * -32;

i.56_172: [0, +INF]  EQUIVALENCES: { } (0 elements)
D.12872_173: [0, 0]  EQUIVALENCES: { } (0 elements)


In light of that, it would appear that the comment

  if (cmp == -2 || cmp == 1)
    {
      /* If the new range has its limits swapped around (MIN > MAX),
	 then the operation caused one of them to wrap around, mark
	 the new range VARYING.  */
      set_value_range_to_varying (vr);
    }

doesn't take into account this kind of MULT_EXPR.

-- 
Eric Botcazou

Attachment: expmed.c.gz
Description: GNU Zip compressed data


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