]> git.ipfire.org Git - thirdparty/gcc.git/commit
simplify-rtx: Fix up simplify_logical_relational_operation [PR119002]
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 4 Mar 2025 10:44:34 +0000 (10:44 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 4 Mar 2025 10:44:34 +0000 (10:44 +0000)
commit1ff01a88c484775fe8b5f1ca46fa24dfe0b14f3d
tree42d0f593eb8246b05997e488f4067a774032a45d
parentccf9db9a6fa4b5bc7aad5e9603e2ac71984142a0
simplify-rtx: Fix up simplify_logical_relational_operation [PR119002]

The following testcase is miscompiled on powerpc64le-linux starting with
r15-6777.  During combine we see:

(set (reg:SI 134)
    (ior:SI (ge:SI (reg:CCFP 128)
            (const_int 0 [0]))
        (lt:SI (reg:CCFP 128)
            (const_int 0 [0]))))

The simplify_logical_relational_operation code (in its current form)
was written with arithmetic rather than CC modes in mind.  Since CCFP
is a CC mode, it fails the HONOR_NANS check, and so the function assumes
that ge | lt => true.

If one comparison is unsigned then it should be safe to assume that
the other comparison is also unsigned, even for CC modes, since the
optimisation checks that the comparisons are between the same operands.
For the other cases, we can only safely fold comparisons of CC mode
values if the result is always-true (15) or always-false (0).

It turns out that the original testcase for PR117186, which ran at -O,
was relying on the old behaviour for some of the functions.  It needs
4-instruction combinations, and so -fexpensive-optimizations, to pass
in its intended form.

gcc/
PR rtl-optimization/119002
* simplify-rtx.cc
(simplify_context::simplify_logical_relational_operation): Handle
comparisons between CC values.  If there is no evidence that the
CC values are unsigned, restrict the fold to always-true or
always-false results.

gcc/testsuite/
* gcc.c-torture/execute/ieee/pr119002.c: New test.
* gcc.target/aarch64/pr117186.c: Run at -O2 rather than -O.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
gcc/simplify-rtx.cc
gcc/testsuite/gcc.c-torture/execute/ieee/pr119002.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr117186.c