From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id C76D63858C3A for ; Thu, 4 Nov 2021 07:47:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C76D63858C3A Received: by mail-ed1-x531.google.com with SMTP id ee33so18312153edb.8 for ; Thu, 04 Nov 2021 00:47:20 -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; bh=9DBBPxZSidoXBbBM+g1cXIyvu2/ha3XD/Ph3vVuVyGc=; b=yUWJwUHTqMyPW4BxyV5YygJW/kJ5uXZlgKyJAAi5Td4UAsCcVyoMvSG+0CA0y5J+Nk ca7SIB9l4q1BZtfTwFnLxt3/qbeJdJbqT3sFbBDEhOrgBtnINJPXEWlGp5/GTvJVW2Y6 BeSj2fa5Wngqt6G7YPrjhLlCTFChN1w0Mv2K87PEjx+LNGIqBHNwZ6MeSAIVx/Vl0glQ lB1zY9kfcpffkwEsNAeqA0ytmTr+hrOBDDWrNaphzq3TxNG0zO5SkNxAoyKVPuyBDq+D WajeFDQXYx7nnGR8IJi7UQ/qVwArEJNnaU5koFSNQF954UV4Rd5WfIZDee8IjHBcvtz8 d+Kw== X-Gm-Message-State: AOAM530BW9DbCtKdZUhaaCXgP5YOzb6ovUfndSttPavTWU8t4mlEeAtU nCZLwSj/KpznxKbabvonjz/+78AG2bbwLewjIwI= X-Google-Smtp-Source: ABdhPJzYDz9K/pFTg2FhmJMm5H2hxt/HAj9CEBWzxVtTQ/l8QwxYz/lDLQYTrX1QpJE/Yw5UPjiN8BZ3dPLpe9pX0RM= X-Received: by 2002:aa7:c656:: with SMTP id z22mr57430416edr.251.1636012039358; Thu, 04 Nov 2021 00:47:19 -0700 (PDT) MIME-Version: 1.0 References: <20211104064510.93649-1-hongtao.liu@intel.com> In-Reply-To: <20211104064510.93649-1-hongtao.liu@intel.com> From: Richard Biener Date: Thu, 4 Nov 2021 08:47:08 +0100 Message-ID: Subject: Re: [PATCH 1/2] [Middle-end] Simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a,b). To: liuhongt Cc: GCC Patches , Hongtao Liu , "H. J. Lu" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.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: Thu, 04 Nov 2021 07:47:22 -0000 On Thu, Nov 4, 2021 at 7:45 AM liuhongt wrote: > > 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? OK. Richard. > 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 } } */ > -- > 2.18.1 >