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

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> ---
Created attachment 66273
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66273&action=edit
AI generated patch based on the analysis

For the latter failing case:

=========== BB 2 ============
Imports: x_10(D)
Exports: _3  _4  _5  x_10(D)  w_11
         _3 : x_10(D)(I)  
         _4 : x_10(D)(I)  w_11
         _5 : _3  _4  x_10(D)(I)  w_11
         w_11 : x_10(D)(I)  
x_10(D) [frange] _Float64 VARYING +-NAN
    <bb 2> :
    w_11 = (_Float128) x_10(D);
    _3 = x_10(D) >= -6.4e+1;
    _4 = w_11 <=
7.19077253944926363091722076315609893447190791576922629094e+308;
    _5 = _3 & _4;
    if (_5 != 0)
      goto <bb 3>; [INV]
    else 
      goto <bb 6>; [INV]

2->3  (T) _3 :  [irange] bool [1, 1]
2->3  (T) _4 :  [irange] bool [1, 1]
2->3  (T) _5 :  [irange] bool [1, 1]
2->3  (T) x_10(D) :     [frange] _Float64 [-6.4e+1 (-0x0.8p+7), +Inf]
2->3  (T) w_11 :        [frange] _Float128 [-Inf,
7.19077253944926363091722076315609893447190791576922629094e+308 (0x0.8p+1027)]
2->6  (F) _5 :  [irange] bool [0, 0]
2->6  (F) x_10(D) :     [frange] _Float64 [-Inf,
-6.40000000000000142108547152020037174224853515625e+1
(-0x0.80000000000008p+7)][+Inf, +Inf] +-NAN


the outgoing expression gets the lower bound of x_10 correctly because [1,1] =
x_10(D) >= -6.4e+1; set that, but the upper bound has to see through the cast
to a (_Float128) of x_10, and we do not appear to do that.  instead, we get an
upper bound of +Inf for x_10.     Then we cannot later eliminate the branch :
if (_6 u<= 1.79769313486231570814527423731704356798070567525844996599e+308)
and the link_failure call remains.

notice that w_11 does get the upper bound correct.  but during the op1_range
for operator cast, we utilize fold_range in a narrowing capacity so we end up
introducing the infiinity even though we dont need to.

Being floating point, I don't understand many of the intricacies involved...  
so I  got some additional input:    I can give you the AI description :-)

----- claude opus 5.0 -----

A cast never manufactures an infinity: (WIDER)X is +-INF only when X is.
FOLD_RANGE was run in the narrowing direction above, so an LHS bound which
overflows TYPE saturated to an infinity which is not actually in the result
set.  Pull such a bound back to the largest finite value TYPE can hold.

This is decided per bound, which is valid only because a cast is unary.
float_binary_op_range_finish has to make the same decision for both bounds
together, as X * -1 maps +INF to -INF, so it cannot drop +INF on the strength
of a finite upper bound alone.

THe AI generated patch which fixes it is attached, someone else can look at and
rewrite as appropriate.

Reply via email to