tree-chrec.c (chrec_convert_aggressive): Do not eliminate conversions where TYPE_MIN_...
authorJeff Law <law@redhat.com>
Tue, 28 Feb 2006 16:49:12 +0000 (09:49 -0700)
committerJeff Law <law@gcc.gnu.org>
Tue, 28 Feb 2006 16:49:12 +0000 (09:49 -0700)
        * tree-chrec.c (chrec_convert_aggressive): Do not eliminate
        conversions where TYPE_MIN_VALUE/TYPE_MAX_VALUE do not cover
        the range allowed by TYPE_PRECISION.

From-SVN: r111568

gcc/ChangeLog
gcc/tree-chrec.c

index 3484670a0a6924540345e3e1f5a0bd7f4e264f64..7ba31346670429aa8907f6bfb5c158426db4d605 100644 (file)
@@ -1,5 +1,9 @@
 2006-02-28  Jeff Law  <law@redhat.com>
 
+       * tree-chrec.c (chrec_convert_aggressive): Do not eliminate
+       conversions where TYPE_MIN_VALUE/TYPE_MAX_VALUE do not cover
+       the range allowed by TYPE_PRECISION.
+
        * tree.h (strct phi_arg_d): Remove unused NONZERO field.
 
 2006-02-28  Dorit Nuzman  <dorit@il.ibm.com>
index b1587a5f91d3070107d9dd203c1312394b62c2a3..8edc5b9bbec0803354f9e2057d77d5c704b21ca5 100644 (file)
@@ -1219,6 +1219,26 @@ chrec_convert_aggressive (tree type, tree chrec)
   if (!rc)
     rc = chrec_convert (type, right, NULL_TREE);
 
+  /* Ada creates sub-types where TYPE_MIN_VALUE/TYPE_MAX_VALUE do not
+     cover the entire range of values allowed by TYPE_PRECISION.
+
+     We do not want to optimize away conversions to such types.  Long
+     term I'd rather see the Ada front-end fixed.  */
+  if (INTEGRAL_TYPE_P (type))
+    {
+      tree t;
+
+      t = upper_bound_in_type (type, inner_type);
+      if (! TYPE_MAX_VALUE (type)
+         || ! operand_equal_p (TYPE_MAX_VALUE (type), t, 0))
+       return NULL_TREE;
+
+      t = lower_bound_in_type (type, inner_type);
+      if (! TYPE_MIN_VALUE (type)
+         || ! operand_equal_p (TYPE_MIN_VALUE (type), t, 0))
+       return NULL_TREE;
+    }
+  
   return build_polynomial_chrec (CHREC_VARIABLE (chrec), lc, rc);
 }