From patchwork Mon Oct 25 05:59:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 46591 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F4FB385841E for ; Mon, 25 Oct 2021 05:59:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F4FB385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635141588; bh=LKF7/JzoVEmelye5EOfkFot9eZZBheME/SePv466X+g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=D10SqPvsJlnrehgYpAxYeRVWdbjfcabui8iBUOmfsNqHyay29MYJRntid/o6ruTdD YrbkbiydOzCtJKvTKCIjsUeV0Q/7XaBnQq2FGqkbxdJkWUkThXVekho1q6+WvWIKxI PKox4kb46MZpv/XzMksq+KtqQQa4jQrxu+g2K+XM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by sourceware.org (Postfix) with ESMTPS id 16D683858C27 for ; Mon, 25 Oct 2021 05:59:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16D683858C27 X-IronPort-AV: E=McAfee;i="6200,9189,10147"; a="293036725" X-IronPort-AV: E=Sophos;i="5.87,179,1631602800"; d="scan'208";a="293036725" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2021 22:59:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,179,1631602800"; d="scan'208";a="596345770" Received: from scymds01.sc.intel.com ([10.148.94.138]) by orsmga004.jf.intel.com with ESMTP; 24 Oct 2021 22:59:16 -0700 Received: from shliclel051.sh.intel.com (shliclel051.sh.intel.com [10.239.236.51]) by scymds01.sc.intel.com with ESMTP id 19P5xFP7015552; Sun, 24 Oct 2021 22:59:15 -0700 To: gcc-patches@gcc.gnu.org Subject: [PATCH] Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value. Date: Mon, 25 Oct 2021 13:59:14 +0800 Message-Id: <20211025055914.76795-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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-Patchwork-Original-From: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Similar for sqrt/sqrtl. gcc/ChangeLog: PR target/102464 * match.pd: Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when direct_internal_fn_supported_p, similar for sqrt/sqrtl. gcc/testsuite/ChangeLog: PR target/102464 * gcc.target/i386/pr102464-sqrtph.c: New test. * gcc.target/i386/pr102464-sqrtsh.c: New test. --- gcc/match.pd | 6 +++-- .../gcc.target/i386/pr102464-sqrtph.c | 27 +++++++++++++++++++ .../gcc.target/i386/pr102464-sqrtsh.c | 23 ++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c diff --git a/gcc/match.pd b/gcc/match.pd index 5bed2e12715..43d1c1bc0bd 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6228,14 +6228,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) 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) + BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF + BUILT_IN_SQRTL BUILT_IN_SQRT BUILT_IN_SQRTF) 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) + IFN_RINT IFN_RINT IFN_RINT + IFN_SQRT IFN_SQRT IFN_SQRT) /* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc., if x is a _Float16. */ (simplify diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c new file mode 100644 index 00000000000..8bd19c6e65e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c @@ -0,0 +1,27 @@ +/* PR target/102464. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize" } */ + +#include +void foo1 (_Float16* __restrict a, _Float16* b) +{ + for (int i = 0; i != 8; i++) + a[i] = sqrtf (b[i]); +} + +void foo2 (_Float16* __restrict a, _Float16* b) +{ + for (int i = 0; i != 8; i++) + a[i] = sqrt (b[i]); +} + +void foo3 (_Float16* __restrict a, _Float16* b) +{ + for (int i = 0; i != 8; i++) + a[i] = sqrtl (b[i]); +} + +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */ +/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */ +/* { dg-final { scan-assembler-not "extendhfxf" } } */ +/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*xmm\[0-9\]" 3 } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c new file mode 100644 index 00000000000..4cf0089a67f --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c @@ -0,0 +1,23 @@ +/* PR target/102464. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx512fp16 -ffast-math" } */ + +#include +_Float16 foo1 (_Float16 a) +{ + return sqrtf (a); +} + +_Float16 foo2 (_Float16 a) +{ + return sqrt (a); +} + +_Float16 foo3 (_Float16 a) +{ + return sqrtl (a); +} + +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */ +/* { dg-final { scan-assembler-not "extendhfxf" } } */ +/* { dg-final { scan-assembler-times "vsqrtsh\[^\n\r\]*xmm\[0-9\]" 3 } } */