From patchwork Wed Jul 27 10:47:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 72841 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp230725qga; Wed, 27 Jul 2016 03:48:10 -0700 (PDT) X-Received: by 10.67.7.165 with SMTP id dd5mr48244411pad.124.1469616490873; Wed, 27 Jul 2016 03:48:10 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id tf1si5862168pab.230.2016.07.27.03.48.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jul 2016 03:48:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-432602-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-432602-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-432602-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=WYm1bwZyww+yMVg m/HvW29Zn+d+BMnry7RK6meV3DwmvtQLE/mIApNoX+GVj7guOPcl23IH3HpAbLBt NpxQRpLtiA9SikiM8ZDPmmIVSYTk9/IV2kFQZ+LE6tZH8FAj92l9J3DZkzCBV41n aEAgBo3u/V/jx+5NDINmwNYjTmKQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=xp2GWTtfFardT96bW2RDA 6Ccy3M=; b=b3WXj8YHeJVVMQvaL3LljRh5cob86U7CstM2Y2ZqxRBUoH4rRq6PS D7vTff8cwvBGScm8z87diYzWMcsEHZMEm9V7s6F4QWKQwDZD+bfgwRsr4V3203yA 8z1STA5yy7v7eBigAhW7UkL1UnqmAI60kqTRmlxJqKA+/zfQM85TAs= Received: (qmail 73901 invoked by alias); 27 Jul 2016 10:47:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 73885 invoked by uid 89); 27 Jul 2016 10:47:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=prathameshkulkarnilinaroorg, prathamesh.kulkarni@linaro.org, 2016-07-27, U*prathamesh.kulkarni X-HELO: mail-it0-f42.google.com Received: from mail-it0-f42.google.com (HELO mail-it0-f42.google.com) (209.85.214.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 27 Jul 2016 10:47:45 +0000 Received: by mail-it0-f42.google.com with SMTP id j124so45949609ith.1 for ; Wed, 27 Jul 2016 03:47:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WovWg9Cmsin5hGwpd16msiW2KmfMuvUux1bnnpCaiz4=; b=JjQMCcB8yTNmrHs1WuaafGqCbAy6IWy6iSiqCoMgPemdKYX33aeOcm52Pe5wa9HY3F bQdgJ5GeYdWA5wAMWKNHOQTsc1vEUyMwviIDgT0X+OLYIxVJQm15YZWt4Ys3QG+PsBbn SbSpJNhek5ww4bT+kQZGazxTeAF125vs+xphdUnlCsl3CUB5vqNxV0JXQziK9STFXOP/ Ed5eG5dcpfHKYPveBnjg4MkEbHyfyO0AYy3vMTcfFp72IUj5sJz+pArJ9SyjOE1dVyG7 B/1+L6T0adChbvlZqUbL6qZs0Rho3j9xGqYNZ71YocSFTjUODee7t4iomhCPhSS93lNY pSEQ== X-Gm-Message-State: AEkoouvoKDNPAmFWNskQuvzGaZ1/ake3fjtHbpsTDoQN528WK0Wppx8zPENx4i3yZPMaUxu+YkNoj/kzQAVSxb9F X-Received: by 10.36.40.144 with SMTP id h138mr16432751ith.31.1469616463113; Wed, 27 Jul 2016 03:47:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.48.197 with HTTP; Wed, 27 Jul 2016 03:47:42 -0700 (PDT) In-Reply-To: References: From: Prathamesh Kulkarni Date: Wed, 27 Jul 2016 16:17:42 +0530 Message-ID: Subject: Re: [PR71078] x / abs(x) -> copysign (1.0, x) To: Richard Biener Cc: gcc Patches , richard.sandiford@arm.com X-IsSubscribed: yes On 26 July 2016 at 17:41, Richard Biener wrote: > On Mon, 25 Jul 2016, Prathamesh Kulkarni wrote: > >> Hi, >> The attached patch tries to fix PR71078. >> I am not sure if I have got the converts right. >> I put (convert? @0) and (convert1? (abs @1)) >> to match for cases when operands's types may >> be different from outermost type like in pr71078-3.c > > Types of RDIV_EXPR have to be the same so as you have a > match on @0 the converts need to be either both present > or not present. > > + (if (FLOAT_TYPE_P (type) > > as you special-case several types below please use SCALAR_FLOAT_TYPE_P > here. > > + && ! HONOR_NANS (type) > + && ! HONOR_INFINITIES (type)) > + (switch > + (if (type == float_type_node) > + (BUILT_IN_COPYSIGNF { build_one_cst (type); } (convert @0))) > > please use if (types_match (type, float_type_node)) instead of > pointer equality. I _think_ you can do better here by using > IFN_COPYSIGN but possibly only so if the target supports it. > Richard - this seems to be the first pattern in need of > generating a builtin where no other was there to match the type > to - any idea how we can safely use the internal function here? > I see those do not have an expander that would fall back to > expanding the regular builtin, correct? > > Please place the pattern next to > > /* Optimize -A / A to -1.0 if we don't care about > NaNs or Infinities. */ > (simplify > (rdiv:C @0 (negate @0)) > (if (FLOAT_TYPE_P (type) > && ! HONOR_NANS (type) > && ! HONOR_INFINITIES (type)) > { build_minus_one_cst (type); })) > > where it logically belongs. Hi, Is this version OK ? Bootstrap + test in progress on x86_64-unknown-linux-gnu. Thanks, Prathamesh > > Thanks, > Richard. > >> test-case (included in patch). >> Bootstrap+test in progress on x86_64-unknown-linux-gnu. >> >> Thanks, >> Prathamesh >> > > -- > Richard Biener > SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg) 2016-07-27 Prathamesh Kulkarni PR middle-end/71078 * match.pd (x / abs(x) -> copysign(1.0, x)): New pattern. testsuite/ * gcc.dg/tree-ssa/pr71078-1.c: New test-case. * gcc.dg/tree-ssa/pr71078-2.c: Likewise. * gcc.dg/tree-ssa/pr71078-3.c: Likewise. diff --git a/gcc/match.pd b/gcc/match.pd index 21bf617..2fd898a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -195,6 +195,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && ! HONOR_INFINITIES (type)) { build_minus_one_cst (type); })) +/* PR71078: x / abs(x) -> copysign (1.0, x) */ +(simplify + (rdiv:C (convert? @0) (convert? (abs @0))) + (if (SCALAR_FLOAT_TYPE_P (type) + && ! HONOR_NANS (type) + && ! HONOR_INFINITIES (type)) + (switch + (if (types_match (type, float_type_node)) + (BUILT_IN_COPYSIGNF { build_one_cst (type); } (convert @0))) + (if (types_match (type, double_type_node)) + (BUILT_IN_COPYSIGN { build_one_cst (type); } (convert @0))) + (if (types_match (type, long_double_type_node)) + (BUILT_IN_COPYSIGNL { build_one_cst (type); } (convert @0)))))) + /* In IEEE floating point, x/1 is not equivalent to x for snans. */ (simplify (rdiv @0 real_onep) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c new file mode 100644 index 0000000..6204c14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math -fdump-tree-forwprop-details" } */ + +#include + +float f1(float x) +{ + float t1 = fabsf (x); + float t2 = x / t1; + return t2; +} + +double f2(double x) +{ + double t1 = fabs (x); + double t2 = x / t1; + return t2; +} + +long double f3 (long double x) +{ + long double t1 = fabsl (x); + long double t2 = x / t1; + return t2; +} + +/* { dg-final { scan-tree-dump "__builtin_copysignf" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "__builtin_copysign" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "__builtin_copysignl" "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c new file mode 100644 index 0000000..96485af --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math -fdump-tree-forwprop-details" } */ + +#include + +float f1(float x) +{ + float t1 = fabsf (x); + float t2 = t1 / x; + return t2; +} + +double f2(double x) +{ + double t1 = fabs (x); + double t2 = t1 / x; + return t2; +} + +long double f3 (long double x) +{ + long double t1 = fabsl (x); + long double t2 = t1 / x; + return t2; +} + +/* { dg-final { scan-tree-dump "__builtin_copysignf" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "__builtin_copysign" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "__builtin_copysignl" "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c new file mode 100644 index 0000000..8780b6a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-3.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math -fdump-tree-forwprop-details" } */ + +#include +double f(float f) +{ + double t1 = fabs(f); + double t2 = f / t1; + return t2; +} + +/* { dg-final { scan-tree-dump "__builtin_copysign" "forwprop1" } } */