From patchwork Mon Aug 1 06:03:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 73079 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2526347qga; Sun, 31 Jul 2016 23:04:20 -0700 (PDT) X-Received: by 10.66.48.133 with SMTP id l5mr92059085pan.151.1470031460607; Sun, 31 Jul 2016 23:04:20 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id rx5si33304488pab.143.2016.07.31.23.04.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jul 2016 23:04:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-432885-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-432885-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-432885-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=eiAWv8BOHQk/8TA KmY3LtIU4VP2tyokaeBCs6y6nG8vkaZnxEZM0WZk4OyRTWeEJY5LLswZyu3OAI/r PWDlCJftVvpctNaCHp7/5QfcAvf26o7pdKlX+YojLiWe5aRQGypNT0MJE+90VY/x SlCo4oN+Z+qC+VM4qKpyURIw+qO4= 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=GChz3V2ET9IfzzHHpb2Dk qRW174=; b=Xy53kBpYaCL5mE8qBuhMW3qelnpn30/cEjLq0HsKhTNm3R2FGmlat B/UELT2x0bezqaMKIUhagIWo/Y5z8u+G1O99LCjIr7WvvUE1u6TyvTZjCPoyYBq9 7zzZm2HAGE6i2FIn9pBlic8C1Yab5GffI+RhIGtGhAU46tmkHKE3cU= Received: (qmail 41478 invoked by alias); 1 Aug 2016 06:04:10 -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 41464 invoked by uid 89); 1 Aug 2016 06:04:08 -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=Sandiford, sandiford, rint, 2016-08-01 X-HELO: mail-it0-f50.google.com Received: from mail-it0-f50.google.com (HELO mail-it0-f50.google.com) (209.85.214.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 01 Aug 2016 06:03:58 +0000 Received: by mail-it0-f50.google.com with SMTP id f6so36186071ith.0 for ; Sun, 31 Jul 2016 23:03:58 -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=jxYXf682k3J8tBS6x7FMbZi7Ibi1xH3SQUgwstaBe+4=; b=CtV+3rB1gBoF0wPW4uiu5FRAzpnXriDyvXTchsj7wDRs0/MnFZaM6Hm2CPeC+xmIaS 20YrwsECJcwP67ZTjl/Lvz2OfU/ohG0pb44ByqVNwpNb1CVtHl3TBD9Eb915xJLiTVxn NhHZVyvTMFpFu677m9iRRfxDwaO9V9AeXp37+bSUpi/MWunG2eL/wQ4D3dlJVkSNLcqj f383P7VqR5xnNPI4wDMBi2a9B+28WXUIqjQ2OU1F6RIokuhL0R7EDiXxDYMgeXidyncD SoGA7PbHTyM6i0S3acNbxelhC1Z7DRtSVU7pt9Pl3GCMTyXXwxuiGteVabH9OHKuwSaR 8XQg== X-Gm-Message-State: AEkooutAzRaGbVy+dh21evOF9Li21to6YDb9spY1cDQxY3yUgaFyIBYMDgnPwJ9a6gmPvMqCcF5S9iirXFWL0Jf6 X-Received: by 10.36.219.65 with SMTP id c62mr11260159itg.44.1470031436592; Sun, 31 Jul 2016 23:03:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.48.197 with HTTP; Sun, 31 Jul 2016 23:03:56 -0700 (PDT) In-Reply-To: References: <8760rsa5lz.fsf@e105548-lin.cambridge.arm.com> From: Prathamesh Kulkarni Date: Mon, 1 Aug 2016 11:33:56 +0530 Message-ID: Subject: Re: [PR71078] x / abs(x) -> copysign (1.0, x) To: Joseph Myers Cc: Richard Sandiford , Richard Biener , gcc Patches X-IsSubscribed: yes On 30 July 2016 at 02:57, Joseph Myers wrote: > On Tue, 26 Jul 2016, Richard Sandiford wrote: > >> (which are really just extended tree codes). I suppose copysign is >> a special case since we can always open code it, but in general we >> shouldn't fall back to something that could generate a call. > > We can't always open code copysign (IBM long double, see PR 58797). Hi, Thanks for pointing that out. The attached patch doesn't transform x/abs(x) -> copysign(1.0, x) for long double. OK for trunk ? Thanks, Prathamesh > > -- > Joseph S. Myers > joseph@codesourcery.com 2016-08-01 Prathamesh Kulkarni * match.pd (x/abs(x) -> copysign(1.0, x)): Don't transform for long double. testsuite/ * gcc.dg/tree-ssa/pr71078-1.c: Remove f3. * gcc.dg/tree-ssa/pr71078-2.c: Likewise. diff --git a/gcc/match.pd b/gcc/match.pd index 2fd898a..3b6aaeb 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -198,17 +198,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* PR71078: x / abs(x) -> copysign (1.0, x) */ (simplify (rdiv:C (convert? @0) (convert? (abs @0))) + /* We can't always transform to copysign for long double. + See PR58797. */ (if (SCALAR_FLOAT_TYPE_P (type) + && ! types_match (type, long_double_type_node) && ! 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)))))) - + (BUILT_IN_COPYSIGN { 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 index 6204c14..4606b2b 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-1.c @@ -17,13 +17,5 @@ double f2(double x) 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 index 96485af..eaff4cc 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71078-2.c @@ -17,13 +17,5 @@ double f2(double 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" } } */