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

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

https://gcc.gnu.org/g:9dac540c7c24afd93a65f100de1cb0ecc25d82a1

commit r16-10040-g9dac540c7c24afd93a65f100de1cb0ecc25d82a1
Author: Hu, Lin1 <[email protected]>
Date:   Tue Dec 1 11:22:50 2026 +0800

    i386: Only use ccmp for SSE math FP compares [PR129188]

    ix86_gen_ccmp_first accepts x87 compares, which give wrong results for
    NaNs in two ways.  Under AVX10.2, ix86_fp_compare_code_to_integer maps
    EQ/NE to ZF alone, which is only correct for VCOMX.  fucomi sets ZF for
    unordered operands, so NaNs compare equal.  Also, reg-stack may swap the
    fcomi operands and apply swap_condition to the integer code of the ccmp
    (GTU <-> LTU), which is not valid for unordered operands.  For example,

      int f (long double a, long double b, int x)
      {
        return x > 0 && !__builtin_isgreaterequal (a, b);
      }

    with -O2 -mapxf gives

            fucomip %st(1), %st
            fstp    %st(0)
            ctestal {dfv=sf, of, zf} %edi, %edi
            setzug  %al

    and f (NaN, 1.0L, 1) returns 0 instead of 1.

    Only use ccmp for SF/DF compares with SSE math and for HF compares.
    Exclude -mfpmath=sse+387, where SF/DF compares may still use fcomi.

    gcc/ChangeLog:

            PR target/129188
            * config/i386/i386-expand.cc (ix86_gen_ccmp_first): Reject x87
            compares.  Only accept SF/DF compares with SSE math and without
            x87 math.

    gcc/testsuite/ChangeLog:

            PR target/129188
            * gcc.target/i386/pr126676.c: Add scan-assembler-not for "ctest".
            * gcc.target/i386/pr129188-1.c: New test.
            * gcc.target/i386/pr129188-2.c: Ditto.
            * gcc.target/i386/pr129188-3.c: Ditto.
            * gcc.target/i386/pr129188-4.c: Ditto.

    (cherry picked from commit e456c4bb65f65192d6da387ef92661b803c9f1d4)

Reply via email to