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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> it seems the code computes fltmax in odd ways and we run into saturation,
> possibly getting undefined float to unsigned int converts (overflow)?
> Possibly the test should use __FLT_MAX__ and friends instead of that
> weird computation.

__FLT_MAX__ is something completely different.
The test attempts to find a largest representable floating point value smaller
or equal than max (and smallest representable floating point value greater or
equal than min).
The problem was that I was relying on
(fltmax = vf2 - vf) == vf2
where fltmax and vf2 are volatile vars to actually store the subtraction and
then read it from the var again, but that is not how we actually gimplify it,
we gimplify it as
float tmp = vf2 - vf; fltmax = tmp; tmp == vf2
and in that case it has the undesirable excess precision behavior.

So, I'd go with
2026-03-02  Jakub Jelinek  <[email protected]>

        PR tree-optimization/124288
        * gcc.dg/torture/vec-cvt-1.c (FLTTEST): Use comma expression
        to store into {flt,dbl}m{in,ax} and read from it again for
        comparison.

--- gcc/testsuite/gcc.dg/torture/vec-cvt-1.c.jj 2026-03-02 11:21:03.545515970
+0100
+++ gcc/testsuite/gcc.dg/torture/vec-cvt-1.c    2026-03-02 14:12:19.190648679
+0100
@@ -55,22 +55,22 @@ flttointtest##intt (void)                                  
        \
   else                                                                 \
     {                                                                  \
       vf2 = fltmin = min - 1.0f;                                       \
-      for (vf = 1.0f; (fltmin = vf2 + vf) == vf2; vf = vf * 2.0f)      \
+      for (vf = 1.0f; fltmin = vf2 + vf, fltmin == vf2; vf = vf * 2.0f)       
\
        ;                                                               \
     }                                                                  \
   vf2 = fltmax = max + 1.0f;                                           \
-  for (vf = 1.0f; (fltmax = vf2 - vf) == vf2; vf = vf * 2.0f)          \
+  for (vf = 1.0f; fltmax = vf2 - vf, fltmax == vf2; vf = vf * 2.0f)    \
     ;                                                                  \
   if (min == 0)                                                               
\
     dblmin = 0.0;                                                      \
   else                                                                 \
     {                                                                  \
       vd2 = dblmin = min - 1.0;                                               
\
-      for (vd = 1.0; (dblmin = vd2 + vd) == vd2; vd = vd * 2.0)               
\
+      for (vd = 1.0; dblmin = vd2 + vd, dblmin == vd2; vd = vd * 2.0)  \
        ;                                                               \
     }                                                                  \
   vd2 = dblmax = max + 1.0;                                            \
-  for (vd = 1.0; (dblmax = vd2 - vd) == vd2; vd = vd * 2.0)            \
+  for (vd = 1.0; dblmax = vd2 - vd, dblmax == vd2; vd = vd * 2.0)      \
     ;                                                                  \
   for (i = 0; i < N; i++)                                              \
     {                                                                  \

Reply via email to