[Bug tree-optimization/109008] [13 Regression] Wrong code in scipy package since r13-3926-gd4c2f1d376da6f

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 9 13:25:10 GMT 2023


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

--- Comment #47 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For the !MODE_HAS_INFINITIES, perhaps
--- gcc/range-op-float.cc.jj    2023-03-09 13:12:05.248873234 +0100
+++ gcc/range-op-float.cc       2023-03-09 14:21:51.959802517 +0100
@@ -2216,6 +2216,7 @@ float_widen_lhs_range (tree type, const
     return ret;
   REAL_VALUE_TYPE lb = lhs.lower_bound ();
   REAL_VALUE_TYPE ub = lhs.upper_bound ();
+  bool lb_inf = false, ub_inf = false;
   if (real_isfinite (&lb))
     {
       frange_nextafter (TYPE_MODE (type), lb, dconstninf);
@@ -2238,6 +2239,14 @@ float_widen_lhs_range (tree type, const
          real_arithmetic (&tem, PLUS_EXPR, &lhs.lower_bound (), &lb);
          real_arithmetic (&lb, RDIV_EXPR, &tem, &dconst2);
        }
+      if (!MODE_HAS_INFINITIES (TYPE_MODE (type))
+         && frange_val_is_min (lhs.lower_bound (), type))
+       {
+         /* If type doesn't have infinities, then the minimum acts
+            as kind of infinity.  Turn it into a true infinity.  */
+         real_inf (&lb, true);
+         lb_inf = true;
+       }
     }
   if (real_isfinite (&ub))
     {
@@ -2256,6 +2265,14 @@ float_widen_lhs_range (tree type, const
          real_arithmetic (&tem, PLUS_EXPR, &lhs.upper_bound (), &ub);
          real_arithmetic (&ub, RDIV_EXPR, &tem, &dconst2);
        }
+      if (!MODE_HAS_INFINITIES (TYPE_MODE (type))
+         && frange_val_is_max (lhs.upper_bound (), type))
+       {
+         /* If type doesn't have infinities, then the maximum acts
+            as kind of infinity.  Turn it into a true infinity.  */
+         real_inf (&ub, false);
+         ub_inf = true;
+       }
     }
   /* Temporarily disable -ffinite-math-only, so that frange::set doesn't
      reduce the range back to real_min_representable (type) as lower bound
@@ -2266,6 +2283,15 @@ float_widen_lhs_range (tree type, const
   ret.clear_nan ();
   ret.union_ (lhs);
   flag_finite_math_only = save_flag_finite_math_only;
+  if (lb_inf || ub_inf)
+    {
+      if (ret.kind () == VR_VARYING)
+       ret.m_kind = VR_RANGE;
+      if (lb_inf)
+       ret.m_min = lb;
+      if (ub_inf)
+       ret.m_max = ub;
+    }
   return ret;
 }

except that the members are private and so the above will not compile.  We'd
need some kind of set_unsafe or whatever that would allow to override those
even when it is not canonical.
But given that I'm not sure if even the forward operations result in correct
ranges around these non-infinity "infinities", doing something with it is
perhaps premature.


More information about the Gcc-bugs mailing list