On Thu, Jul 16, 2026 at 9:26 PM Richard Biener <[email protected]> wrote:
>
> The following makes sure to honor v2df_reduction_prefer_haddpd
> when expanding reduc_plus_scal_V2DF via ix86_expand_reduc.
>
> There is test coverage in gcc.target/i386/pr54400.c
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> OK?
>
> Thanks,
> Richard.
>
>         PR target/126271
>         * config/i386/i386-expand.cc (ix86_expand_reduc): Honor
>         TARGET_V2DF_REDUCTION_PREFER_HADDPD and expand via
>         gen_sse3_haddv2df3.
> ---
>  gcc/config/i386/i386-expand.cc | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> index a448e470f73..0cd4a72256e 100644
> --- a/gcc/config/i386/i386-expand.cc
> +++ b/gcc/config/i386/i386-expand.cc
> @@ -20079,6 +20079,15 @@ ix86_expand_reduc (rtx (*fn) (rtx, rtx, rtx), rtx 
> dest, rtx in)
>        return;
>      }
>
> +  /* SSE3 has haddpd, some targets prefer that over movhlpd plus add.  */
> +  if (TARGET_SSE3
> +      && TARGET_V2DF_REDUCTION_PREFER_HADDPD
> +      && mode == V2DFmode)
Please also add fn == gen_addv2df3 since REDUC_SSE_SMINMAX_MODE also
has V2DFmode.

4029;; Modes handled by reduc_sm{in,ax}* patterns.
4030(define_mode_iterator REDUC_SSE_SMINMAX_MODE
4031  [(V8HF "TARGET_AVX512FP16 && TARGET_AVX512VL")
4032   (V4SF "TARGET_SSE") (V2DF "TARGET_SSE")
4033   (V4SI "TARGET_SSE2") (V8HI "TARGET_SSE2") (V16QI "TARGET_SSE2")
4034   (V2DI "TARGET_SSE4_2")])
4035
4036(define_expand "reduc_<code>_scal_<mode>"
4037  [(smaxmin:REDUC_SSE_SMINMAX_MODE
4038     (match_operand:<ssescalarmode> 0 "register_operand")
4039     (match_operand:REDUC_SSE_SMINMAX_MODE 1 "register_operand"))]
4040  ""
4041{
4042  rtx tmp = gen_reg_rtx (<MODE>mode);
4043  ix86_expand_reduc (gen_<code><mode>3, tmp, operands[1]);
4044  emit_insn (gen_vec_extract<mode><ssescalarmodelower>
(operands[0], tmp,
4045
const0_rtx));
4046  DONE;
4047})


Others LGTM.
> +    {
> +      emit_insn (gen_sse3_haddv2df3 (dest, in, in));
> +      return;
> +    }
> +
>    for (i = GET_MODE_BITSIZE (mode);
>         i > GET_MODE_UNIT_BITSIZE (mode);
>         i >>= 1)
> --
> 2.51.0



-- 
BR,
Hongtao

Reply via email to