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

--- Comment #10 from Aldy Hernandez <aldyh at redhat dot com> ---
> > as well as here:
> >
> >      if (TREE_CODE (val1) == INTEGER_CST && TREE_CODE (val2) == INTEGER_CST)
> >       {
> >         /* We cannot compare overflowed values.  */
> >         if (TREE_OVERFLOW (val1) || TREE_OVERFLOW (val2))
> >           return -2;
> >
> >         return tree_int_cst_compare (val1, val2);
> >       }
>
> VRP uses (used to use) fold_* routines and _specifically_ relies (relied)
> on some TREE_OVERFLOW bits therein.  This might be all long history
> but the above is probably because of that.
>
> Btw, IIRC I've made sure to drop TREE_OVERFLOW from constants picked out
> of the IL for VRP purposes (as said, some passes are "confused" about
> existing TREE_OVERFLOW if they rely on TREE_OVERFLOW for their own
> internal processing - which, nowadays should use wide_int).

Ok, let's let sleeping dogs lie then.  I'll drop the overflow will
building ranges.

Thanks for the explanation.

I'll commit the following if it passes tests.
Aldy

    Drop overflow from constants while building ranges in ranger.

    Sometimes overflow flag will leak into the IL.  Drop them while
    creating ranges.

    gcc/ChangeLog:

            PR tree-optimization/97721
            * gimple-range.cc (get_tree_range): Drop overflow from constants.

    gcc/testsuite/ChangeLog:

            * gcc.dg/pr97721.c: New test.

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index cf979845acf..6d351002830 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -165,6 +165,8 @@ get_tree_range (irange &r, tree expr)
   switch (TREE_CODE (expr))
     {
       case INTEGER_CST:
+    if (TREE_OVERFLOW_P (expr))
+      expr = drop_tree_overflow (expr);
     r.set (expr, expr);
     return true;

diff --git a/gcc/testsuite/gcc.dg/pr97721.c b/gcc/testsuite/gcc.dg/pr97721.c
new file mode 100644
index 00000000000..c2a2848ba13
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97721.c
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-options "-O -fno-tree-dominator-opts" }
+
+int ot;
+
+void
+z6 (char *tw)
+{
+  while (ot >= 0)
+    --ot;
+
+  __builtin_strcpy (&tw[ot], tw);
+}

Reply via email to