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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Indeed it's related.  We now have range-info for

x_16 = x_15(D) + 2;

and thus:

Visiting conditional with predicate: if (x_16 == 0)

With known ranges
        x_16: [-2147483646, +INF]
...
Intersecting
  ~[0, 0]  EQUIVALENCES: { x_16 } (1 elements)
and
  [-2147483646, +INF]
to
  [-2147483646, +INF]  EQUIVALENCES: { x_16 } (1 elements)

arguably the newly chosen range is smaller ...

we don't have the ability (limitation of the equivalence representation)
to keep ~[0, 0] as equivalence and it wouldn't help in this case given
the info is later supposed to be taken from SSA_NAME_RANGE_INFO.

We do special-case ~[0, 0] in the range intersection code but only for
pointer-type sized ranges...

          /* Choose the anti-range if it is ~[0,0], that range is special
             enough to special case when vr1's range is relatively wide.  */
          else if (*vr0min == *vr0max
                   && integer_zerop (*vr0min)
                   && (TYPE_PRECISION (TREE_TYPE (*vr0min))
                       == TYPE_PRECISION (ptr_type_node))
                   && TREE_CODE (vr1max) == INTEGER_CST
                   && TREE_CODE (vr1min) == INTEGER_CST
                   && (wi::clz (wi::to_wide (vr1max) - wi::to_wide (vr1min))
                       < TYPE_PRECISION (TREE_TYPE (*vr0min)) / 2))
            ;

thus a "fix" is (I guess I'm ok with that if it doesn't regress any testcase
we have):

Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c      (revision 255167)
+++ gcc/tree-vrp.c      (working copy)
@@ -6024,8 +6024,6 @@ intersect_ranges (enum value_range_type
             enough to special case when vr1's range is relatively wide.  */
          else if (*vr0min == *vr0max
                   && integer_zerop (*vr0min)
-                  && (TYPE_PRECISION (TREE_TYPE (*vr0min))
-                      == TYPE_PRECISION (ptr_type_node))
                   && TREE_CODE (vr1max) == INTEGER_CST
                   && TREE_CODE (vr1min) == INTEGER_CST
                   && (wi::clz (wi::to_wide (vr1max) - wi::to_wide (vr1min))

Reply via email to