From patchwork Thu Nov 4 06:45:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 47028 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 5D6DD3858416 for ; Thu, 4 Nov 2021 06:45:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D6DD3858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636008345; bh=t7btnQ4akD9vMqQAt2IAu0oNW2von2sPQjOhF6ugoVs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wnnCXozbGKEbhaQYDZljo3ieMZdWGurNiMsSekKgWgKFW7UQx7+pGPkqwDIWD05+g z4i8F5e1cAwnjBrJ1BOTCh863Bw8ANhfZ++O+MtHYBzDvRqyA4JgxWU/0dLiw5Nvh4 lV3TT18jC7U5M/L8vH53rLnBm/kVcz8B0j8sQkaI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id 7C8FE3858C3A for ; Thu, 4 Nov 2021 06:45:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C8FE3858C3A X-IronPort-AV: E=McAfee;i="6200,9189,10157"; a="212402552" X-IronPort-AV: E=Sophos;i="5.87,208,1631602800"; d="scan'208";a="212402552" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2021 23:45:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,208,1631602800"; d="scan'208";a="541975390" Received: from scymds01.sc.intel.com ([10.148.94.138]) by fmsmga008.fm.intel.com with ESMTP; 03 Nov 2021 23:45:13 -0700 Received: from shliclel051.sh.intel.com (shliclel051.sh.intel.com [10.239.236.51]) by scymds01.sc.intel.com with ESMTP id 1A46jB3Q026053; Wed, 3 Nov 2021 23:45:12 -0700 To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] [Middle-end] Simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a, b). Date: Thu, 4 Nov 2021 14:45:09 +0800 Message-Id: <20211104064510.93649-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 X-Spam-Status: No, score=-11.6 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" a and b are same type as the truncation type and has less precision than extend type. Bootstrapped and regtested on x86-64-pc-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR target/102464 * match.pd: simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a,b) when a and b are same type as the truncation type and has less precision than extend type. gcc/testsuite/ChangeLog: * gcc.target/i386/pr102464-copysign-1.c: New test. --- gcc/match.pd | 13 +++ .../gcc.target/i386/pr102464-copysign-1.c | 80 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 0734c45700c..f63079023d0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6169,6 +6169,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && direct_internal_fn_supported_p (as_internal_fn (tos), type, OPTIMIZE_FOR_BOTH)) (tos @0)))) + +/* Simplify (trunc) copysign ((extend)x, (extend)y) to copysignf (x, y), + x,y is float value, similar for _Float16/double. */ +(for copysigns (COPYSIGN_ALL) + (simplify + (convert (copysigns (convert@2 @0) (convert @1))) + (if (optimize + && types_match (type, TREE_TYPE (@0)) + && types_match (type, TREE_TYPE (@1)) + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2)) + && direct_internal_fn_supported_p (IFN_COPYSIGN, + type, OPTIMIZE_FOR_BOTH)) + (IFN_COPYSIGN @0 @1)))) #endif (for froms (XFLOORL XCEILL XROUNDL XRINTL) diff --git a/gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c b/gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c new file mode 100644 index 00000000000..95a39509738 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c @@ -0,0 +1,80 @@ +/* PR target/102464. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ftree-vectorize -mfpmath=sse -fdump-tree-optimized" } */ + +#include +void foo1 (_Float16* __restrict a, _Float16* b, _Float16* c) +{ + for (int i = 0; i != 8; i++) + a[i] = copysignf (b[i], c[i]); +} + +void foo2 (_Float16* __restrict a, _Float16* b, _Float16* c) +{ + for (int i = 0; i != 8; i++) + a[i] = copysign (b[i], c[i]); +} + +void foo3 (_Float16* __restrict a, _Float16* b, _Float16* c) +{ + for (int i = 0; i != 8; i++) + a[i] = copysignl (b[i], c[i]); +} + +void foo4 (float* __restrict a, float* b, float* c) +{ + for (int i = 0; i != 4; i++) + a[i] = copysign (b[i], c[i]); +} + +void foo5 (float* __restrict a, float* b, float* c) +{ + for (int i = 0; i != 4; i++) + a[i] = copysignl (b[i], c[i]); +} + +void foo6 (double* __restrict a, double* b, double* c) +{ + for (int i = 0; i != 4; i++) + a[i] = copysignl (b[i], c[i]); +} + +void foo7 (_Float16* __restrict a, _Float16* b, _Float16* c) +{ + a[0] = copysignf (b[0], c[0]); +} + +void foo8 (_Float16* __restrict a, _Float16* b, _Float16* c) +{ + a[0] = copysign (b[0], c[0]); +} + +void foo9 (_Float16* __restrict a, _Float16* b, _Float16* c) +{ + a[0] = copysignl (b[0], c[0]); +} + +void foo10 (float* __restrict a, float* b, float* c) +{ + a[0] = copysign (b[0], c[0]); +} + +void foo11 (float* __restrict a, float* b, float* c) +{ + a[0] = copysignl (b[0], c[0]); +} + +void foo12 (double* __restrict a, double* b, double* c) +{ + a[0] = copysignl (b[0], c[0]); +} + +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */ +/* { dg-final { scan-assembler-not "vcvtss2sd" } } */ +/* { dg-final { scan-assembler-not "fld" } } */ +/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */ +/* { dg-final { scan-assembler-not "vcvtps2pd" } } */ +/* { dg-final { scan-assembler-not "extendhfxf" } } */ +/* { dg-final { scan-assembler-not "\\\{1to8\\\}" } } */ +/* { dg-final { scan-tree-dump-times "\.COPYSIGN" 12 "optimized" } } */ +/* { dg-final { scan-assembler-times "vpternlog" 12 } } */