From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by sourceware.org (Postfix) with ESMTPS id 9F4FC3858400 for ; Tue, 28 Sep 2021 02:01:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F4FC3858400 Received: by mail-vk1-xa36.google.com with SMTP id s137so7792220vke.11 for ; Mon, 27 Sep 2021 19:01:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=6bpWII1ly7dyZ4IDGP9DSwEt9z8aZG3QOOWSjw1awEg=; b=Y2P/XDuGsiBtCgD+x0+9X7/aINFepAsCCGCIeOWX4mWJkAOrBn+sYqZyjWO9xsQ07g mBZf+aPJrUuCJ2DdYfbX3MMvamC4aas5eOaW/G5PcSFmX0QZxwZk/LjfhvaEfpyYKtnv HBJDiww9MXbntCzqefHRCb4VI4MxndTIfLGDALDI5fVwLRrWFvMIeJA84WaXk70hexxc nelVZ9xhBxXv4201/F9P1kih4tAgBJkTFl6IkMit0NBSxtFSAAQWm5/SyUIcmfKdzDCT s2M0Er9RvZWb4fQILCsu1IR/TEvGankKp5gbWZC2sSzoyHBf45ACm9ydFqKnv1WPWReL //LA== X-Gm-Message-State: AOAM533rkYjj74LzWoH7/iYn1Uodl73wovZZXhVDjzhEPVLY43lm2jKn tnp+xzBrSvdGMle1gG/lw76e2PQC2qjiBBeOGWg= X-Google-Smtp-Source: ABdhPJzzz3fp0c6uS0RcYc0Ap3LQfQpQMNszFpBnVR2N2WOMwL5SV0Skd9q4vkJwDLYxHFJO+vbptaBfpQVWhrZ3VTg= X-Received: by 2002:a1f:13d7:: with SMTP id 206mr3133718vkt.9.1632794502210; Mon, 27 Sep 2021 19:01:42 -0700 (PDT) MIME-Version: 1.0 References: <20210924112552.2524168-1-hongtao.liu@intel.com> In-Reply-To: From: Hongtao Liu Date: Tue, 28 Sep 2021 10:07:54 +0800 Message-ID: Subject: Re: [PATCH] [GIMPLE] Simplify (_Float16) ceil ((double) x) to .CEIL (x) when available. To: Richard Biener Cc: liuhongt , GCC Patches , Uros Bizjak , "H. J. Lu" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.5 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2021 02:01:44 -0000 On Mon, Sep 27, 2021 at 8:53 PM Richard Biener wrote: > > On Fri, Sep 24, 2021 at 1:26 PM liuhongt wrote: > > > > Hi: > > Related discussion in [1] and PR. > > > > Bootstrapped and regtest on x86_64-linux-gnu{-m32,}. > > Ok for trunk? > > > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574330.html > > > > gcc/ChangeLog: > > > > PR target/102464 > > * config/i386/i386.c (ix86_optab_supported_p): > > Return true for HFmode. > > * match.pd: Simplify (_Float16) ceil ((double) x) to > > __builtin_ceilf16 (a) when a is _Float16 type and > > direct_internal_fn_supported_p. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/i386/pr102464.c: New test. > > --- > > gcc/config/i386/i386.c | 20 +++++++----- > > gcc/match.pd | 28 +++++++++++++++++ > > gcc/testsuite/gcc.target/i386/pr102464.c | 39 ++++++++++++++++++++++++ > > 3 files changed, 79 insertions(+), 8 deletions(-) > > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464.c > > > > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c > > index ba89e111d28..3767fe9806d 100644 > > --- a/gcc/config/i386/i386.c > > +++ b/gcc/config/i386/i386.c > > @@ -23582,20 +23582,24 @@ ix86_optab_supported_p (int op, machine_mode = mode1, machine_mode, > > return opt_type =3D=3D OPTIMIZE_FOR_SPEED; > > > > case rint_optab: > > - if (SSE_FLOAT_MODE_P (mode1) > > - && TARGET_SSE_MATH > > - && !flag_trapping_math > > - && !TARGET_SSE4_1) > > + if (mode1 =3D=3D HFmode) > > + return true; > > + else if (SSE_FLOAT_MODE_P (mode1) > > + && TARGET_SSE_MATH > > + && !flag_trapping_math > > + && !TARGET_SSE4_1) > > return opt_type =3D=3D OPTIMIZE_FOR_SPEED; > > return true; > > > > case floor_optab: > > case ceil_optab: > > case btrunc_optab: > > - if (SSE_FLOAT_MODE_P (mode1) > > - && TARGET_SSE_MATH > > - && !flag_trapping_math > > - && TARGET_SSE4_1) > > + if (mode1 =3D=3D HFmode) > > + return true; > > + else if (SSE_FLOAT_MODE_P (mode1) > > + && TARGET_SSE_MATH > > + && !flag_trapping_math > > + && TARGET_SSE4_1) > > return true; > > return opt_type =3D=3D OPTIMIZE_FOR_SPEED; > > > > diff --git a/gcc/match.pd b/gcc/match.pd > > index a9791ceb74a..9ccec8b6ce3 100644 > > --- a/gcc/match.pd > > +++ b/gcc/match.pd > > @@ -6191,6 +6191,34 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > (froms (convert float_value_p@0)) > > (convert (tos @0))))) > > > > +#if GIMPLE > > +(match float16_value_p > > + @0 > > + (if (TYPE_MAIN_VARIANT (TREE_TYPE (@0)) =3D=3D float16_type_node))) > > +(for froms (BUILT_IN_TRUNCL BUILT_IN_TRUNC BUILT_IN_TRUNCF > > + BUILT_IN_FLOORL BUILT_IN_FLOOR BUILT_IN_FLOORF > > + BUILT_IN_CEILL BUILT_IN_CEIL BUILT_IN_CEILF > > + BUILT_IN_ROUNDEVENL BUILT_IN_ROUNDEVEN BUILT_IN_ROUNDEVENF > > + BUILT_IN_ROUNDL BUILT_IN_ROUND BUILT_IN_ROUNDF > > + BUILT_IN_NEARBYINTL BUILT_IN_NEARBYINT BUILT_IN_NEARBYINTF > > + BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF) > > we do have patterns that convert (truncl (convert floatval)) to > (float)truncf (val), > your's does (_Float16)trunc ((double) float16) -> truncF16 (float16), doe= sn't it > make sense to have trunc ((double) float16) -> (double)trunfF16 > (float16) as well? > > Why do you conditionalize on GIMPLE here? To avoid error: =E2=80=98direct_internal_fn_supported_p=E2=80=99 was not declared in= this scope > > That said, I wonder whether we can somehow address pattern explosion here= , > eliding the outer (convert ...) from the match would help a bit already. > > The related patterns use optimize && canonicalize_math_p as well btw., no= t > sure whether either is appropriate here since there are no _Float16 math > functions available. Yes, that's why I didn't follow the existing pattern, i think we can add optimize back to the condition, but not canonicalize_math_p () since there's no math function for _Float16. Also w/o the outer (convert ..), it looks like a canonicalization to transform ceil ((double) a) to (double) __builtin_ceilf16 (a) but not an optimization. > > > + tos (IFN_TRUNC IFN_TRUNC IFN_TRUNC > > + IFN_FLOOR IFN_FLOOR IFN_FLOOR > > + IFN_CEIL IFN_CEIL IFN_CEIL > > + IFN_ROUNDEVEN IFN_ROUNDEVEN IFN_ROUNDEVEN > > + IFN_ROUND IFN_ROUND IFN_ROUND > > + IFN_NEARBYINT IFN_NEARBYINT IFN_NEARBYINT > > + IFN_RINT IFN_RINT IFN_RINT) > > + /* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc., > > + if x is a _Float16. */ > > + (simplify > > + (convert (froms (convert float16_value_p@0))) > > + (if (types_match (type, TREE_TYPE (@0)) > > + && direct_internal_fn_supported_p (as_internal_fn (tos), > > + type, OPTIMIZE_FOR_BOTH)) > > + (tos @0)))) > > +#endif > > + > > (for froms (XFLOORL XCEILL XROUNDL XRINTL) > > tos (XFLOOR XCEIL XROUND XRINT) > > /* llfloorl(extend(x)) -> llfloor(x), etc., if x is a double. */ > > diff --git a/gcc/testsuite/gcc.target/i386/pr102464.c b/gcc/testsuite/g= cc.target/i386/pr102464.c > > new file mode 100644 > > index 00000000000..e3e060ee80b > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/i386/pr102464.c > > @@ -0,0 +1,39 @@ > > +/* PR target/102464. */ > > +/* { dg-do compile } */ > > +/* { dg-options "-O2 -mavx512fp16" } */ > > + > > +#define FOO(FUNC,SUFFIX) \ > > + _Float16 \ > > + foo_##FUNC##_##SUFFIX (_Float16 a) \ > > + { \ > > + return __builtin_##FUNC##SUFFIX (a); \ > > + } > > + > > +FOO (roundeven, f16); > > +FOO (roundeven, f); > > +FOO (roundeven, ); > > +FOO (roundeven, l); > > +FOO (trunc, f16); > > +FOO (trunc, f); > > +FOO (trunc, ); > > +FOO (trunc, l); > > +FOO (ceil, f16); > > +FOO (ceil, f); > > +FOO (ceil, ); > > +FOO (ceil, l); > > +FOO (floor, f16); > > +FOO (floor, f); > > +FOO (floor, ); > > +FOO (floor, l); > > +FOO (nearbyint, f16); > > +FOO (nearbyint, f); > > +FOO (nearbyint, ); > > +FOO (nearbyint, l); > > +FOO (rint, f16); > > +FOO (rint, f); > > +FOO (rint, ); > > +FOO (rint, l); > > + > > +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */ > > +/* { dg-final { scan-assembler-not "extendhfxf" } } */ > > +/* { dg-final { scan-assembler-times "vrndscalesh\[^\n\r\]*xmm\[0-9\]"= 24 } } */ > > -- > > 2.27.0 > > --=20 BR, Hongtao