range_int_cst_p handling in extract_range_from_binary_expr_1
authorRichard Sandiford <richard.sandiford@linaro.org>
Fri, 22 Sep 2017 17:00:56 +0000 (17:00 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Fri, 22 Sep 2017 17:00:56 +0000 (17:00 +0000)
extract_range_from_binary_expr_1 had:

      if (range_int_cst_p (&vr0)
          && range_int_cst_p (&vr1)
          && TYPE_OVERFLOW_WRAPS (expr_type))
        ...
      ...
      extract_range_from_multiplicative_op_1 (vr, code, &vr0, &vr1);

but extract_range_from_multiplicative_op_1 also requires range_int_cst_p.
I think we should bail out if either range isn't a constant.

This might only be theoretical with current sources, but it's needed
once polynomial constants are added.

2017-09-22  Richard Sandiford  <richard.sandiford@linaro.org>
    Alan Hayward  <alan.hayward@arm.com>
    David Sherwood  <david.sherwood@arm.com>

gcc/
* tree-vrp.c (extract_range_from_multiplicative_op_1): Assert
for VR_RANGE only; don't allow VR_ANTI_RANGE.
(extract_range_from_binary_expr_1): Don't call
extract_range_from_multiplicative_op_1 if !range_int_cst_p.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>
From-SVN: r253102

gcc/ChangeLog
gcc/tree-vrp.c

index e29256106b2c42d83c9138af30b3f65df96e3eeb..fdb7221848ce5027a6fe49bc4dde52f11d1bb403 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-22  Richard Sandiford  <richard.sandiford@linaro.org>
+           Alan Hayward  <alan.hayward@arm.com>
+           David Sherwood  <david.sherwood@arm.com>
+
+       * tree-vrp.c (extract_range_from_multiplicative_op_1): Assert
+       for VR_RANGE only; don't allow VR_ANTI_RANGE.
+       (extract_range_from_binary_expr_1): Don't call
+       extract_range_from_multiplicative_op_1 if !range_int_cst_p.
+
 2017-09-22  Richard Sandiford  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index aef20f4e8a5a71336c39d5186848904dff9c8623..3dba35627893e7af44109c3388c89f4997d0e7f0 100644 (file)
@@ -1851,8 +1851,7 @@ extract_range_from_multiplicative_op_1 (value_range *vr,
              || code == ROUND_DIV_EXPR
              || code == RSHIFT_EXPR
              || code == LSHIFT_EXPR);
-  gcc_assert ((vr0->type == VR_RANGE
-              || (code == MULT_EXPR && vr0->type == VR_ANTI_RANGE))
+  gcc_assert (vr0->type == VR_RANGE
              && vr0->type == vr1->type);
 
   rtype = vr0->type;
@@ -2462,9 +2461,14 @@ extract_range_from_binary_expr_1 (value_range *vr,
       signop sign = TYPE_SIGN (expr_type);
       unsigned int prec = TYPE_PRECISION (expr_type);
 
-      if (range_int_cst_p (&vr0)
-         && range_int_cst_p (&vr1)
-         && TYPE_OVERFLOW_WRAPS (expr_type))
+      if (!range_int_cst_p (&vr0)
+         || !range_int_cst_p (&vr1))
+       {
+         set_value_range_to_varying (vr);
+         return;
+       }
+
+      if (TYPE_OVERFLOW_WRAPS (expr_type))
        {
          typedef FIXED_WIDE_INT (WIDE_INT_MAX_PRECISION * 2) vrp_int;
          typedef generic_wide_int