From patchwork Mon Jan 10 11:34:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 49796 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 6DF0F3896C16 for ; Mon, 10 Jan 2022 11:34:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DF0F3896C16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641814490; bh=sCu793oY3OM5Xhs61hR+kOXVp3lnwA8Xfc6cy8t/17A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=RJTrcv4lfCHVW012Jl0tS6IhxmzQ3GUEXdYDiveNVvH/qsc7/tcQRJ9gBFDpPCljS f3lZeWfcyLzDCaX+r3QomOSBH3equ0vE/rKublIYzRk3e202KOoWv5tpgf3Bd70Rpw ObexUvLIioAfRysdHYx/zm6voETHZPZdLKJ79EnI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 7A15D3896C04 for ; Mon, 10 Jan 2022 11:34:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A15D3896C04 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20A9FIVR019405 for ; Mon, 10 Jan 2022 03:34:18 -0800 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3dg7nkt3ys-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Mon, 10 Jan 2022 03:34:18 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 10 Jan 2022 03:34:17 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 10 Jan 2022 03:34:17 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id C37AF3F70A9; Mon, 10 Jan 2022 03:34:16 -0800 (PST) To: Subject: [PATCH] [aarch64/64821]: Simplify __builtin_aarch64_sqrt* into internal function .SQRT. Date: Mon, 10 Jan 2022 03:34:12 -0800 Message-ID: <1641814452-23872-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: KpIUGC39xnGNOyKH24HPMx9c6CguyNE0 X-Proofpoint-ORIG-GUID: KpIUGC39xnGNOyKH24HPMx9c6CguyNE0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-10_05,2022-01-10_01,2021-12-02_01 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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-Patchwork-Original-From: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski This is a simple patch which simplifies the __builtin_aarch64_sqrt* builtins into the internal function SQRT which allows for constant folding and other optimizations at the gimple level. It was originally suggested we do to __builtin_sqrt just for __builtin_aarch64_sqrtdf when -fno-math-errno but since r6-4969-g686ee9719a4 we have the internal function SQRT which does the same so it makes we don't need to check -fno-math-errno either now. OK? Bootstrapped and tested on aarch64-linux-gnu with no regressions. PR target/64821 gcc/ChangeLog: * config/aarch64/aarch64-builtins.c (aarch64_general_gimple_fold_builtin): Handle __builtin_aarch64_sqrt* and simplify into SQRT internal function. gcc/testsuite/ChangeLog: * gcc.target/aarch64/vsqrt-1.c: New test. * gcc.target/aarch64/vsqrt-2.c: New test. --- gcc/config/aarch64/aarch64-builtins.c | 7 ++++++ gcc/testsuite/gcc.target/aarch64/vsqrt-1.c | 17 +++++++++++++ gcc/testsuite/gcc.target/aarch64/vsqrt-2.c | 28 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/vsqrt-1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/vsqrt-2.c diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c index 58bcbd9875f..1bf487477eb 100644 --- a/gcc/config/aarch64/aarch64-builtins.c +++ b/gcc/config/aarch64/aarch64-builtins.c @@ -2820,6 +2820,13 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt, gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); break; + /* Lower sqrt builtins to gimple/internal function sqrt. */ + BUILTIN_VHSDF_DF (UNOP, sqrt, 2, FP) + new_stmt = gimple_build_call_internal (IFN_SQRT, + 1, args[0]); + gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); + break; + /*lower store and load neon builtins to gimple. */ BUILTIN_VALL_F16 (LOAD1, ld1, 0, LOAD) BUILTIN_VDQ_I (LOAD1_U, ld1, 0, LOAD) diff --git a/gcc/testsuite/gcc.target/aarch64/vsqrt-1.c b/gcc/testsuite/gcc.target/aarch64/vsqrt-1.c new file mode 100644 index 00000000000..3207c8774ca --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/vsqrt-1.c @@ -0,0 +1,17 @@ +/* PR target/64821 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* Check that we constant fold sqrt(4.0) into 2.0. */ +/* { dg-final { scan-tree-dump-times ".SQRT" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "2.0" 1 "optimized" } } */ +/* { dg-final { scan-assembler-times "fsqrt" 0 } } */ +/* We should produce a fmov to d0 with 2.0 but currently don't, see PR 103959. */ +/* { dg-final { scan-assembler-times "\n\tfmov\td0, 2.0e.0" 1 { xfail *-*-* } } } */ + +#include + +float64x1_t f64(void) +{ + float64x1_t a = (float64x1_t){4.0}; + return vsqrt_f64 (a); +} diff --git a/gcc/testsuite/gcc.target/aarch64/vsqrt-2.c b/gcc/testsuite/gcc.target/aarch64/vsqrt-2.c new file mode 100644 index 00000000000..7465b79f3a7 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/vsqrt-2.c @@ -0,0 +1,28 @@ +/* PR target/64821 */ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-optimized" } */ +#include + +/* Check that we lower __builtin_aarch64_sqrt* into the internal function SQRT. */ +/* { dg-final { scan-tree-dump-times "__builtin_aarch64" 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times ".SQRT" 4 "optimized" } } */ + +float64x1_t f64(float64x1_t a) +{ + return vsqrt_f64 (a); +} + +float64x2_t f64q(float64x2_t a) +{ + return vsqrtq_f64 (a); +} + +float32x2_t f32(float32x2_t a) +{ + return vsqrt_f32 (a); +} + +float32x4_t f32q(float32x4_t a) +{ + return vsqrtq_f32 (a); +}