Re: [PATCH] i386: Don't use VCOMX for XFmode compares

Uros Bizjak <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <CAFULd4Z42P_HoUnrqDvyJeq5_JaO61U-Kksf1p061kwygibSQg@mail.gmail.com>
On Mon, Aug 10, 2026 at 9:03 AM Hu, Lin1 <[email protected]> wrote:
>
> Hi, all
>
> v{,u}comx insn only support DF/SF/HF mode, add extra mode checking during
> optimisation.
>
> Bootstrapped and regtested on x86-64-pc-linux, OK for trunk?
>
> BRs,
> Lin
>
> gcc/ChangeLog:
>
>         PR target/126676
>         * config/i386/i386-expand.cc (ix86_expand_fp_compare): Only use
>         UNSPEC_OPTCOMX for the modes VCOMX exists for.
>
> gcc/testsuite/ChangeLog:
>
>         PR target/126676
>         * gcc.target/i386/pr126676.c: New test.

LGTM.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386-expand.cc           | 15 ++++++++-------
>  gcc/testsuite/gcc.target/i386/pr126676.c |  7 +++++++
>  2 files changed, 15 insertions(+), 7 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr126676.c
>
> diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> index d0b92efc48b..fb4224af0da 100644
> --- a/gcc/config/i386/i386-expand.cc
> +++ b/gcc/config/i386/i386-expand.cc
> @@ -2922,6 +2922,7 @@ ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1)
>    rtx tmp, scratch;
>
>    code = ix86_prepare_fp_compare_args (code, &op0, &op1);
> +  machine_mode op_mode = GET_MODE (op0);
>
>    tmp = gen_rtx_COMPARE (CCFPmode, op0, op1);
>    if (unordered_compare)
> @@ -2932,14 +2933,14 @@ ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1)
>      {
>      case IX86_FPCMP_COMI:
>        tmp = gen_rtx_COMPARE (CCFPmode, op0, op1);
> +      /* VCOMX/VUCOMX only have DF/SF/HF mode instructions.  */
> +      if (TARGET_AVX10_2
> +         && (code == EQ || code == NE)
> +         && (op_mode == HFmode || op_mode == SFmode || op_mode == DFmode))
> +       tmp = gen_rtx_UNSPEC (CCFPmode, gen_rtvec (1, tmp), UNSPEC_OPTCOMX);
>        /* We only have vcomisbf16, No vcomubf16 nor vcomxbf16 */
> -      if (GET_MODE (op0) != E_BFmode)
> -       {
> -         if (TARGET_AVX10_2 && (code == EQ || code == NE))
> -           tmp = gen_rtx_UNSPEC (CCFPmode, gen_rtvec (1, tmp), UNSPEC_OPTCOMX);
> -         if (unordered_compare)
> -           tmp = gen_rtx_UNSPEC (CCFPmode, gen_rtvec (1, tmp), UNSPEC_NOTRAP);
> -       }
> +      if (op_mode != BFmode && unordered_compare)
> +       tmp = gen_rtx_UNSPEC (CCFPmode, gen_rtvec (1, tmp), UNSPEC_NOTRAP);
>        cmp_mode = CCFPmode;
>        emit_insn (gen_rtx_SET (gen_rtx_REG (CCFPmode, FLAGS_REG), tmp));
>        break;
> diff --git a/gcc/testsuite/gcc.target/i386/pr126676.c b/gcc/testsuite/gcc.target/i386/pr126676.c
> new file mode 100644
> index 00000000000..219a6133790
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr126676.c
> @@ -0,0 +1,7 @@
> +/* { dg-do compile { target { ! ia32 } } } */
> +/* { dg-options "-O2 -march=x86-64 -mavx10.2 -mapxf" } */
> +/* { dg-final { scan-assembler-times "fucomip" 2 } } */
> +/* { dg-final { scan-assembler-not "comx" } } */
> +
> +int f1 (long double a, long double b, int x) { return x > 0 && a == b; }
> +int f2 (long double a, long double b, int x) { return x > 0 && a != b; }
> --
> 2.31.1
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.