From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id BB7BE3858D1E for ; Tue, 20 Jun 2023 08:41:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB7BE3858D1E 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-x235.google.com with SMTP id 38308e7fff4ca-2b46cad2fd9so38521581fa.1 for ; Tue, 20 Jun 2023 01:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687250500; x=1689842500; 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=o76MP0TrutTYJbYnj/d+tzgEcbXXDbDvoGRP1NtZj0k=; b=DslyAXP4z6oZy6cb1Dry+pyFUgYQO5NFXRiolOLsKNzwIIzFNzVzHUv2cOPow2xL0a mpXrerRW+UbGTfjWMAFiTU/zy4GteI0aFH0fmLoOswNFEREBUlgHVXiAvmKgEA9r4K2s DCjoVhEf0JXuiJu4wbOygHe05fqI4Tt35wghcBfRXBFNBb1N9/lnQiF2A2wcTnOJlFlO G8Vb2C1J6gCQpceExaukP/Jwaa+p9molx4D+TfP0T4Uybs/Lzc11PLcHakSUe5qE8Atp nqmTp5Qh/VGyNmZDaVR7GXYJjGnSi8vL4EwDNKAZRtANx+QH/FwzAKRaQ9poEMptf7en gGfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687250500; x=1689842500; 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=o76MP0TrutTYJbYnj/d+tzgEcbXXDbDvoGRP1NtZj0k=; b=BPkmGPAZzUzWo5x00vCo0jf8yroVV+KQFWt9tNz6iuBFThmaGqU0fNcxlODuxa4QMB ghRbB46njN5ZGzx3Al74SBfmgY61PAH+QlocI3KUhLC774NW4fH0csNxMJKfcvui3Mk8 b7324Xe5Jt6S7/i1QP4UrDhKnPd93qpArkiCt+EvHP991SDwBJX4FWLSPl+sK/X5N6mI WwPUBTz/KWj5vdbLous+cBo1ZjdsMZVK1AvKjqQxzzZa3Rz2fQ9NB1xj3xuQ33qjRw/4 1WCkpotga8GYOvREI4B4BrF1xS2a3KqPVwzqDV5W35WBRuHDMLrWGGS2ljYxxT5B2aXJ mHwA== X-Gm-Message-State: AC+VfDwf40jmKM2o0rO7QRx5Bgd2JRfGfJ/Rk0lPaKiEqjIgfmuwtcwJ mNyGlZlKX59tuzKaOgYGkWlYqlSB0Fy4YAZ8mRE= X-Google-Smtp-Source: ACHHUZ7RRxk6JirQ4jd19rS2lp5RRDC+jTLy1G+qsoIVj4LU4GkBF85Xd7vdrxPLtRwj4HmlS9mR8RWvrAfMkiIA0ss= X-Received: by 2002:a2e:8887:0:b0:2b4:8239:b12d with SMTP id k7-20020a2e8887000000b002b48239b12dmr2329597lji.0.1687250499779; Tue, 20 Jun 2023 01:41:39 -0700 (PDT) MIME-Version: 1.0 References: <20230602010015.2571612-1-hongtao.liu@intel.com> In-Reply-To: <20230602010015.2571612-1-hongtao.liu@intel.com> From: Richard Biener Date: Tue, 20 Jun 2023 10:38:44 +0200 Message-ID: Subject: Re: [PATCH] [vect]Use intermiediate integer type for float_expr/fix_trunc_expr when direct optab is not existed. To: liuhongt Cc: gcc-patches@gcc.gnu.org, crazylht@gmail.com, hjl.tools@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.6 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 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 optabs > 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/testsuite/g= cc.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 whether w= e 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 (imo= de), > + 0); > + cvt_type =3D get_vectype_for_scalar_type (vinfo, cvt_type, > + slp_node); > + /* This should only happened for SLP as long as loop vector= izer > + only supports same-sized vector. */ > + if (cvt_type =3D=3D NULL_TREE > + || maybe_ne (TYPE_VECTOR_SUBPARTS (cvt_type), nunits_in= ) > + || !supportable_convert_operation (code1, vectype_out, > + cvt_type, &code1) > + || !supportable_convert_operation (codecvt1, cvt_type, > + vectype_in, &codecvt= 1)) > + 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, vop= 0); > + gassign* new_stmt; > + if (multi_step_cvt) > + { > + gcc_assert (multi_step_cvt =3D=3D 1); > + new_stmt =3D gimple_build_assign (vec_dest, codecvt1, vop0)= ; > + 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 the intermediate conversion and not involve interm_types[0]? Otherwise looks good. Thanks, Richard. > + gimple_assign_set_lhs (new_stmt, new_temp); > + vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gs= i); > + vop0 =3D new_temp; > + vec_dest =3D vec_dsts[0]; > + } > + 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, gsi); > -- > 2.39.1.388.g2fc9e9ca3c >