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

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Andrew Pinski
<[email protected]>:

https://gcc.gnu.org/g:8f163f4027736e98af0128b302ae8df49252a70b

commit r16-9120-g8f163f4027736e98af0128b302ae8df49252a70b
Author: Andrew Pinski <[email protected]>
Date:   Sat Jun 13 14:42:30 2026 -0700

    range fold: Fix relation folding of |/& when reversed operands [PR125774]

    This showed up in GCC 13 in the original testcase but became latent in GCC
14.
    So I created a simple gimple testcase to show the issue.
    So what we have is:
      _21 = _20 > lower_9;
      _22 = lower_9 > _20;
      _23 = _21 | _22;

    And this would incorrectly be folded into 1 and that is because we treated
one of
    those `>` as `<=` rather than as just `<`. This was due to an incorrect use
    of relation_negate rather than relation_swap when dealing with swapping the
operands.

    Pushed as obvious after a bootstrap/test on x86_64-linux-gnu.

            PR tree-optimization/125774

    gcc/ChangeLog:

            * gimple-range-fold.cc (fold_using_range::relation_fold_and_or):
Use
            relation_swap rather than relation_negate when the operands are
exchanged.

    gcc/testsuite/ChangeLog:

            * gcc.dg/torture/pr125774-1.c: New test.

    Signed-off-by: Andrew Pinski <[email protected]>
    (cherry picked from commit 905d407ee4b23c749fa00d0cf3b0aed551a07f36)

Reply via email to