[Bug tree-optimization/105189] [9/10 Regression] Wrong code with -O1

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 11 06:26:21 GMT 2022


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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

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

commit r9-10146-gcddca3b79f813f2140f2f485de33ef90d7a03740
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 8 09:14:44 2022 +0200

    fold-const: Fix up make_range_step [PR105189]

    The following testcase is miscompiled, because fold_truth_andor
    incorrectly folds
    (unsigned) foo () >= 0U && 1
    into
    foo () >= 0
    For the unsigned comparison (which is useless in this case,
    as >= 0U is always true, but hasn't been folded yet), previous
    make_range_step derives exp (unsigned) foo () and +[0U, -]
    range for it.  Next we process the NOP_EXPR.  We have special code
    for unsigned to signed casts, already earlier punt if low or high
    aren't representable in arg0_type or if it is a narrowing conversion.
    For the signed to unsigned casts, I think if high is specified we
    are still fine, as we punt for non-representable values in arg0_type,
    n_high is then still representable and so was smaller or equal to
    signed maximum and either low is not present (equivalent to 0U), or
    low must be smaller or equal to high and so for unsigned exp
    +[low, high] the signed exp +[n_low, n_high] will be correct.
    Similarly, if both low and high aren't specified (always true or
    always false), it is ok too.
    But if we have for unsigned exp +[low, -] or -[low, -], using
    +[n_low, -] or -[n_high, -] is incorrect.  Because low is smaller
    or equal to signed maximum and high is unspecified (i.e. unsigned
    maximum), when signed that range is a union of +[n_low, -] and
    +[-, -1] which is equivalent to -[0, n_low-1], unless low
    is 0, in that case we can treat it as [-, -].

    2022-04-08  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/105189
            * fold-const.c (make_range_step): Fix up handling of
            (unsigned) x +[low, -] ranges for signed x if low fits into
            typeof (x).

            * g++.dg/torture/pr105189.C: New test.

    (cherry picked from commit 5e6597064b0c7eb93b8f720afc4aa970eefb0628)


More information about the Gcc-bugs mailing list