On Thu, Oct 8, 2026 at 5:06 PM Roger Sayle <[email protected]> wrote:
>
>
> This patch provides SSE implementations of __builtin_fmin and
> __builtin_fmax.  The one tricky aspect is that x86's v{max,min}{sd,ss}
> functions don't quite implement the IEEE specification for fmax and
> fmin, for example, they aren't commutative in the presence of NaNs.
> Hence a correct implementation requires an additional unordered
> comparison to check if the second operand to min/max is NaN,
> and if so use a vpblend to return the correct NaN.
>
> Hence for the simple test case:
>
> double foo(double x, double y)
> {
>   return __builtin_fmax (x,y);
> }
>
> with -O2 -mavx, we now generate:
>
> foo:    vmaxsd  %xmm1, %xmm0, %xmm1
>         vcmpunordsd     %xmm0, %xmm0, %xmm2
>         vblendvpd       %xmm2, %xmm0, %xmm1, %xmm0
>
> [which happens to match what clang/llvm generates].
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}
> with no new failures.  Ok for mainline?

IIRC the expander is also used by the vectorizer, so the mode iterator
should also include vector float modes?

>
>
> 2026-10-08  Roger Sayle  <[email protected]>
>
> gcc/ChangeLog
>         * config/i386/i386.c (ix86_optab_supported_p): Add fmax_optab
>         and fmin_optab cases to continue calling fmax/fmin with -Os.
>         * config/i386/i386.md (maxmin_unspec_ieee): New code attribute
>         to map smax and smin to the corresponding UNSPEC_IEEE_{MAX,MIN}.
>         * config/i386/sse.md (f<maxmin_float><mode>3): New define_expand
>         for fmax<mode>3 and fmin<mode3> using *ieee_{smax,smin}<mode>3.
>
> gcc/testsuite/ChangeLog
>         * gcc.target/i386/builtin-fmax-1.c: New test case.
>         * gcc.target/i386/builtin-fmin-1.c: Likewise.
>
>
> Thanks in advance,
> Roger
> --
>

Reply via email to