Add missing int_cst_rangeN checks to tree-vrp.c
authorRichard Sandiford <richard.sandiford@linaro.org>
Thu, 21 Sep 2017 10:53:40 +0000 (10:53 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Thu, 21 Sep 2017 10:53:40 +0000 (10:53 +0000)
The BIT_AND_EXPR handling in extract_range_from_binary_expr_1
was using value_range_constant_singleton without first checking
whether the range was a constant.  The earlier handling was correctly
guarded:

  /* If either input range contains only non-negative values
     we can truncate the result range maximum to the respective
     maximum of the input range.  */
  if (int_cst_range0 && tree_int_cst_sgn (vr0.min) >= 0)
    wmax = wi::min (wmax, vr0.max, TYPE_SIGN (expr_type));
  if (int_cst_range1 && tree_int_cst_sgn (vr1.min) >= 0)
    wmax = wi::min (wmax, vr1.max, TYPE_SIGN (expr_type));

so this patch uses the same guards again.

Existing tests showed the need for this once polynomial constants
are added.

2017-09-21  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_binary_expr_1): Check
int_cst_rangeN before calling value_range_constant_singleton (&vrN).

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

gcc/ChangeLog
gcc/tree-vrp.c

index 80803d622948bd98e60aaff51e8d00b4b90d4781..3861e6603e31d02f164e8bd12ae9797b91d42412 100644 (file)
@@ -1,3 +1,10 @@
+2017-09-21  Richard Sandiford  <richard.sandiford@linaro.org>
+           Alan Hayward  <alan.hayward@arm.com>
+           David Sherwood  <david.sherwood@arm.com>
+
+       * tree-vrp.c (extract_range_from_binary_expr_1): Check
+       int_cst_rangeN before calling value_range_constant_singleton (&vrN).
+
 2017-09-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/71351
index 221a07b6b3fc6ae3cc737d4fc0c811d614e9a705..1d45851ea924ddfdd5cc190e6a24fcf69149b294 100644 (file)
@@ -2930,9 +2930,11 @@ extract_range_from_binary_expr_1 (value_range *vr,
                = wi::set_bit_in_zero (TYPE_PRECISION (expr_type) - 1,
                                       TYPE_PRECISION (expr_type));
              if (!TYPE_UNSIGNED (expr_type)
-                 && ((value_range_constant_singleton (&vr0)
+                 && ((int_cst_range0
+                      && value_range_constant_singleton (&vr0)
                       && !wi::cmps (vr0.min, sign_bit))
-                     || (value_range_constant_singleton (&vr1)
+                     || (int_cst_range1
+                         && value_range_constant_singleton (&vr1)
                          && !wi::cmps (vr1.min, sign_bit))))
                {
                  min = TYPE_MIN_VALUE (expr_type);