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

--- Comment #39 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:bad177e848787258070415dbe002b2c6fba1c511

commit r13-6549-gbad177e848787258070415dbe002b2c6fba1c511
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Mar 9 09:51:37 2023 +0100

    range-op-float: Fix up reverse binary operations [PR109008]

    The following testcase is reduced from miscompilation of scipy package.
    If we have say lhs = [1., 1.] - [1., 1.] and want to compute the range
    of lhs from it, we correctly determine it is [0., 0.] (if computations
    are exact, we generally don't try to round them further in
    frange_arithmetic).  In the testcase it is about a reverse operation,
    [1., 1.] = op1 + [1., 1.] and we want to compute range of op1 from that.
    Right now we just perform the inverse operation (there are some corner
    cases about NaN and infinities handling) and so arrive to range
    [0., 0.] as well, and because it is a singleton, optimize return eps;
    to return 0.  That is incorrect though, for the reverse ops we need to
    take into account also rounding, the right exact range is
    [-0x1.0p-54, 0x1.0p-53] in this case when rounding to nearest, i.e.
    all numbers which added to 1. with round to nearest still produce 1.

    The problem isn't solely on singleton ranges, and isn't solely on
    results around zero.  We basically need to consider also values
    where the result is up to 0.5ulp away from the lhs range boundaries
    in each direction.

    The following patch fixes it by extending the lhs range for the
    reverse operations by 1ulp in each direction.  The PR contains
    a pseudo-random test generator I've used to generate 300000 tests
    of + and - and then used the same test with * and / instead of + and -
    together with a hack to print the discovered ranges by the patch in
    a form that another test could then verify the range is conservatively
    correct and how far it is from a minimal range.

    I believe the results are good enough for now, though plan to look
    incrementally into trying to do something better on the -XXX_MAX or
    XXX_MAX boundaries (where I think frange_nextafter will use -inf or +inf)
    and also try to increase the range just by 0.5ulp rather than 1ulp
    if !flag_rounding_math.  But dunno if either of those will be doable
    and will pass the testing, so I think it is worth committing this fix
    first.

    2023-03-09  Jakub Jelinek  <ja...@redhat.com>
                Richard Biener  <rguent...@suse.de>

            PR tree-optimization/109008
            * range-op-float.cc (float_widen_lhs_range): New function.
            (foperator_plus::op1_range, foperator_minus::op1_range,
            foperator_minus::op2_range, foperator_mult::op1_range,
            foperator_div::op1_range, foperator_div::op2_range): Use it.

            * gcc.c-torture/execute/ieee/pr109008.c: New test.

Reply via email to