https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87059

--- Comment #20 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Aldy Hernandez from comment #18)
> BTW, the suggest patch in comment 10 causes an x86-64 regression on
> gcc.dg/attr-nonstring-3.c because of some incompatibility with ssizetype and
> sizetype.  I believe it's related to this:
> 
> https://gcc.gnu.org/ml/gcc/2018-08/msg00164.html
> 
> ...so it may be a rat's nest to fix.  I may just make VRP work with broken
> behavior it expected before.

Testing the following.

gcc/

        PR 87059/tree-optimization
        * tree-vrp.c (extract_range_from_binary_expr_1): Pass sign of
        first argument to wide_int_range_min_max.

diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 735b3646e81..7373011d901 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -1566,6 +1566,15 @@ extract_range_from_binary_expr_1 (value_range *vr,
       wide_int vr1_min, vr1_max;
       extract_range_into_wide_ints (&vr0, sign, prec, vr0_min, vr0_max);
       extract_range_into_wide_ints (&vr1, sign, prec, vr1_min, vr1_max);
+
+      /* FIXME: Currently the sign of MIN_EXPR and the sign of its
+        arguments are not always the same.  Fixing the creators of
+        these faulty nodes caused other problems.  For now use the
+        sign of the first argument as VRP was previously doing.  See
+        PR87059.  */
+      if (vr0.min)
+       sign = TYPE_SIGN (TREE_TYPE (vr0.min));
+
       if (wide_int_range_min_max (wmin, wmax, code, sign, prec,
                                  vr0_min, vr0_max, vr1_min, vr1_max))
        set_value_range (vr, VR_RANGE,

Reply via email to