From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 16E953858D1E for ; Tue, 20 Jun 2023 09:25:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16E953858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2b47742de92so29883261fa.0 for ; Tue, 20 Jun 2023 02:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687253135; x=1689845135; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KQSaZgDv0X34Qhvp8aStQ2NRQlc92z0EM9IRNAKQV40=; b=VYNd65MwdEIfT0eq1zsCF+/lRZXe4hOLn+z11e1ysAuyWQp83ACZXpw0zWvbua5rkI oL1dX0LVBFiKQy2dNbecx9Ne30JQIpHeONd0plCVINv2NaMpvYfW+TULoymXXBlBu5rp /fgKpWV/SgCtJSYcqKgE1X7EamyKRJ2jPYiJ1t2ln4QZUZAgOuLbKB9tMsvGFef4homi /zY5y8eq5lu2PMIIelJ7LMXYkYyf7ulRXG07h7o9Dy1uH+JSog2Evoc6Bwyvlo3NcJQi C2AM0ikK8H5VvyBWp2DlXk4eYyFo5/hNYjvgq3YTIVXk5IB34dPExjhwEggM3RYsOVJc XrFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687253135; x=1689845135; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KQSaZgDv0X34Qhvp8aStQ2NRQlc92z0EM9IRNAKQV40=; b=fmmDLCCRrdoeIzNSA8ypoiCebrzbjQoMjRoOzZUykyzyMR6Pr7EePwegbmRuy/a4N8 1G+GpZRTF9aYphABQrVfrlvDKpH0Gk+fWkEiyT8/DQ3m7JuSI9+CWVy5R/w4hoWZ/wtS fLfnkdnSLRl7WEz15jD96Ycr2mjF9joB3hVjAWlj+9uO3xkJMhmRXwqWQWgD4Q34KMW4 z1jXtrhwbK/z0UhWPkRiNH49txzErmpvkOilhghFG/IZmcy4PMoV2+TXYJuTLgGSzwZb RAU5c7VUVOPoDuHINC2purDdMNg24pIKgTIxEZsggHyluO9LaSGlVx/2Hq84hydmJ/xe tnhw== X-Gm-Message-State: AC+VfDyAnCKyznS8vzSi59RPqZoO/wSDkZoTftxOX9CYshOaM80IoBpE gC+zJdXDSBSuuYHkjjmJsOZZpvWMAFuShy4zD64= X-Google-Smtp-Source: ACHHUZ5PiTUOvAWf295P81GzLOYqRtdJkC5DPquVOJZm/PtcIvi7zTS/VQLPMxCqjfnQ81qBLrf9YQngM/LYAWjU3GE= X-Received: by 2002:a05:651c:1207:b0:2b4:78f6:d335 with SMTP id i7-20020a05651c120700b002b478f6d335mr2942532lja.8.1687253135170; Tue, 20 Jun 2023 02:25:35 -0700 (PDT) MIME-Version: 1.0 References: <20230602010015.2571612-1-hongtao.liu@intel.com> In-Reply-To: From: Richard Biener Date: Tue, 20 Jun 2023 11:22:39 +0200 Message-ID: Subject: Re: [PATCH] [vect]Use intermiediate integer type for float_expr/fix_trunc_expr when direct optab is not existed. To: Hongtao Liu Cc: liuhongt , gcc-patches@gcc.gnu.org, hjl.tools@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Jun 20, 2023 at 11:02=E2=80=AFAM Hongtao Liu w= rote: > > On Tue, Jun 20, 2023 at 4:41=E2=80=AFPM Richard Biener > wrote: > > > > On Fri, Jun 2, 2023 at 3:01=E2=80=AFAM liuhongt via Gcc-patches > > wrote: > > > > > > We have already use intermidate type in case WIDEN, but not for NONE, > > > this patch extended that. > > > > > > I didn't do that in pattern recog since we need to know whether the > > > stmt belongs to any slp_node to decide the vectype, the related optab= s > > > are checked according to vectype_in and vectype_out. For non-slp case= , > > > vec_pack/unpack are always used when lhs has different size from rhs, > > > for slp case, sometimes vec_pack/unpack is used, somethings > > > direct conversion is used. > > > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. > > > Ok for trunk? > > > > > > gcc/ChangeLog: > > > > > > PR target/110018 > > > * tree-vect-stmts.cc (vectorizable_conversion): Use > > > intermiediate integer type for float_expr/fix_trunc_expr when > > > direct optab is not existed. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * gcc.target/i386/pr110018-1.c: New test. > > > --- > > > gcc/testsuite/gcc.target/i386/pr110018-1.c | 94 ++++++++++++++++++++= ++ > > > gcc/tree-vect-stmts.cc | 56 ++++++++++++- > > > 2 files changed, 149 insertions(+), 1 deletion(-) > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr110018-1.c > > > > > > diff --git a/gcc/testsuite/gcc.target/i386/pr110018-1.c b/gcc/testsui= te/gcc.target/i386/pr110018-1.c > > > new file mode 100644 > > > index 00000000000..b1baffd7af1 > > > --- /dev/null > > > +++ b/gcc/testsuite/gcc.target/i386/pr110018-1.c > > > @@ -0,0 +1,94 @@ > > > +/* { dg-do compile } */ > > > +/* { dg-options "-mavx512fp16 -mavx512vl -O2 -mavx512dq" } */ > > > +/* { dg-final { scan-assembler-times {(?n)vcvttp[dsh]2[dqw]} 5 } } *= / > > > +/* { dg-final { scan-assembler-times {(?n)vcvt[dqw]*2p[dsh]} 5 } } *= / > > > + > > > +void > > > +foo (double* __restrict a, char* b) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > +} > > > + > > > +void > > > +foo1 (float* __restrict a, char* b) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > + a[2] =3D b[2]; > > > + a[3] =3D b[3]; > > > +} > > > + > > > +void > > > +foo2 (_Float16* __restrict a, char* b) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > + a[2] =3D b[2]; > > > + a[3] =3D b[3]; > > > + a[4] =3D b[4]; > > > + a[5] =3D b[5]; > > > + a[6] =3D b[6]; > > > + a[7] =3D b[7]; > > > +} > > > + > > > +void > > > +foo3 (double* __restrict a, short* b) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > +} > > > + > > > +void > > > +foo4 (float* __restrict a, char* b) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > + a[2] =3D b[2]; > > > + a[3] =3D b[3]; > > > +} > > > + > > > +void > > > +foo5 (double* __restrict b, char* a) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > +} > > > + > > > +void > > > +foo6 (float* __restrict b, char* a) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > + a[2] =3D b[2]; > > > + a[3] =3D b[3]; > > > +} > > > + > > > +void > > > +foo7 (_Float16* __restrict b, char* a) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > + a[2] =3D b[2]; > > > + a[3] =3D b[3]; > > > + a[4] =3D b[4]; > > > + a[5] =3D b[5]; > > > + a[6] =3D b[6]; > > > + a[7] =3D b[7]; > > > +} > > > + > > > +void > > > +foo8 (double* __restrict b, short* a) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > +} > > > + > > > +void > > > +foo9 (float* __restrict b, char* a) > > > +{ > > > + a[0] =3D b[0]; > > > + a[1] =3D b[1]; > > > + a[2] =3D b[2]; > > > + a[3] =3D b[3]; > > > +} > > > diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc > > > index bd3b07a3aa1..1118c89686d 100644 > > > --- a/gcc/tree-vect-stmts.cc > > > +++ b/gcc/tree-vect-stmts.cc > > > @@ -5162,6 +5162,49 @@ vectorizable_conversion (vec_info *vinfo, > > > return false; > > > if (supportable_convert_operation (code, vectype_out, vectype_= in, &code1)) > > > break; > > > > A comment would be nice here. Like > > > > /* For conversions between float and smaller integer types try wheth= er we can > > use intermediate signed integer types to support the conversion. = */ > > > > > + if ((code =3D=3D FLOAT_EXPR > > > + && GET_MODE_SIZE (lhs_mode) > GET_MODE_SIZE (rhs_mode)) > > > + || (code =3D=3D FIX_TRUNC_EXPR > > > + && GET_MODE_SIZE (rhs_mode) > GET_MODE_SIZE (lhs_mode))= ) > > > + { > > > + bool float_expr_p =3D code =3D=3D FLOAT_EXPR; > > > + scalar_mode imode =3D float_expr_p ? rhs_mode : lhs_mode; > > > + fltsz =3D GET_MODE_SIZE (float_expr_p ? lhs_mode : rhs_mode= ); > > > + code1 =3D float_expr_p ? code : NOP_EXPR; > > > + codecvt1 =3D float_expr_p ? NOP_EXPR : code; > > > + FOR_EACH_2XWIDER_MODE (rhs_mode_iter, imode) > > > + { > > > + imode =3D rhs_mode_iter.require (); > > > + if (GET_MODE_SIZE (imode) > fltsz) > > > + break; > > > + > > > + cvt_type > > > + =3D build_nonstandard_integer_type (GET_MODE_BITSIZE = (imode), > > > + 0); > > > + cvt_type =3D get_vectype_for_scalar_type (vinfo, cvt_ty= pe, > > > + slp_node); > > > + /* This should only happened for SLP as long as loop ve= ctorizer > > > + only supports same-sized vector. */ > > > + if (cvt_type =3D=3D NULL_TREE > > > + || maybe_ne (TYPE_VECTOR_SUBPARTS (cvt_type), nunit= s_in) > > > + || !supportable_convert_operation (code1, vectype_o= ut, > > > + cvt_type, &code1= ) > > > + || !supportable_convert_operation (codecvt1, cvt_ty= pe, > > > + vectype_in, &cod= ecvt1)) > > > + continue; > > > + > > > + found_mode =3D true; > > > + break; > > > + } > > > + > > > + if (found_mode) > > > + { > > > + multi_step_cvt++; > > > + interm_types.safe_push (cvt_type); > > > + cvt_type =3D NULL_TREE; > > > + break; > > > + } > > > + } > > > /* FALLTHRU */ > > > unsupported: > > > if (dump_enabled_p ()) > > > @@ -5381,7 +5424,18 @@ vectorizable_conversion (vec_info *vinfo, > > > { > > > /* Arguments are ready, create the new vector stmt. */ > > > gcc_assert (TREE_CODE_LENGTH (code1) =3D=3D unary_op); > > > - gassign *new_stmt =3D gimple_build_assign (vec_dest, code1,= vop0); > > > + gassign* new_stmt; > > > + if (multi_step_cvt) > > > + { > > > + gcc_assert (multi_step_cvt =3D=3D 1); > > > + new_stmt =3D gimple_build_assign (vec_dest, codecvt1, v= op0); > > > + new_temp =3D make_ssa_name (vec_dest, new_stmt); > > > > I wonder how you get away with using vec_dest both for the final and th= e > > intermediate conversion and not involve interm_types[0]? > interm_types[0] is assigned to vect_dest, the original > vect_dest(vectype_out) is pushed to vec_dsts. > > auto_vec vec_dsts (multi_step_cvt + 1); > vec_dest =3D vect_create_destination_var (scalar_dest, > (cvt_type && modifier =3D=3D WIDEN) > ? cvt_type : vectype_out); > vec_dsts.quick_push (vec_dest); > > if (multi_step_cvt) > { > for (i =3D interm_types.length () - 1; > interm_types.iterate (i, &intermediate_type); i--) > { > vec_dest =3D vect_create_destination_var (scalar_dest, > intermediate_type); > vec_dsts.quick_push (vec_dest); > } > } > > > > > Otherwise looks good. > Thanks for review. > > > > Thanks, > > Richard. > > > > > + gimple_assign_set_lhs (new_stmt, new_temp); > > > + vect_finish_stmt_generation (vinfo, stmt_info, new_stmt= , gsi); > > > + vop0 =3D new_temp; > > > + vec_dest =3D vec_dsts[0]; > And it's assigned back to vec_dest here. Ah, subtle. So the patch is OK with the added comment. Thanks, Richard. > > > + } > > > + new_stmt =3D gimple_build_assign (vec_dest, code1, vop0); > > > new_temp =3D make_ssa_name (vec_dest, new_stmt); > > > gimple_assign_set_lhs (new_stmt, new_temp); > > > vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gs= i); > > > -- > > > 2.39.1.388.g2fc9e9ca3c > > > > > > > -- > BR, > Hongtao