From patchwork Mon Jul 25 14:23:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 72732 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1174557qga; Mon, 25 Jul 2016 07:23:37 -0700 (PDT) X-Received: by 10.98.68.1 with SMTP id r1mr12037195pfa.161.1469456617530; Mon, 25 Jul 2016 07:23:37 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l4si33904738pap.106.2016.07.25.07.23.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jul 2016 07:23:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-432459-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-432459-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-432459-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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=EfQGOzq2qmajc73E4x2SI9ukAuWW2Pb6qRCkpYBAOhL9la Asw0ylF4TsuAFXK9uBO8iIO0j9EbvJyJlPHNJ2baVNtAapMTr8RYe1bDj9N1YCHt u9yAlo7zNkvkmJETCLqAUtyhlCubdQcWo/0wRKjqU5RMGlxcDCdXRD93n6raY= 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:from:date:message-id:subject:to:content-type; s= default; bh=tpKlvkaY+3wPCKsMVBKVmywDTKc=; b=VvbObASLCtq7mLyvExAe zVwICwtqbiguk62OP7MySxcpgZhSV4JfEsc2SFlJlc+wJ00969RHEF0KcD95Om+n K6oB0qmbOVm3kCMlYoD6yET+ToSUy1pA+YrkjKvRHio5UowEKI7iDjpRFW3p8dOT UDQSfDrluAcz2mWsO0FAzYA= Received: (qmail 39659 invoked by alias); 25 Jul 2016 14:23:25 -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 39645 invoked by uid 89); 25 Jul 2016 14:23:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f178.google.com Received: from mail-io0-f178.google.com (HELO mail-io0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 25 Jul 2016 14:23:14 +0000 Received: by mail-io0-f178.google.com with SMTP id m101so162564203ioi.2 for ; Mon, 25 Jul 2016 07:23:14 -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:from:date:message-id:subject:to; bh=OLaLGq1TTjzHS8YNlx+CoYjwQ3pxFvT/IavfkmhsNDM=; b=eWen7wA7KC8klz0i3S+xhIJlrqf9ofuvOdZAp0GDuDBdEeBP1/lcITaoZZKj8tbNFn jMucoUcuUv8NeER57+oKxc0159u+yQHUXLDFi1vkjJovngyzV0n28IFFbHVT9UK4PcfQ i79Dn0rQQ3zpK2bv+T3zl76JVabHMtCu1XCAbQtI/DtYhbjMBVu+lY8JtKGE2llltFD2 gSKVQMuprEb11cNfc2uQ9bSzAOgK/uM4csF4MuXzS7WHhMP5Xa/Z1ch+sQJLpvlpAT7+ nc2Slkeu1fhX255XHyg/EhYkpidbcWrNgCltpH9K1mlnQzjhBBZHAt0ncKKaBI2bmuG5 +88A== X-Gm-Message-State: AEkoouumacIzCBNjOpJ14MhCLFuQKRROUM2AYW/WS8+pfWDq4VbHGYGZaZct1J+5aTFGYAexJKFXJZ7hLeeAn1gg X-Received: by 10.107.159.147 with SMTP id i141mr19742962ioe.29.1469456592552; Mon, 25 Jul 2016 07:23:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.48.197 with HTTP; Mon, 25 Jul 2016 07:23:11 -0700 (PDT) From: Prathamesh Kulkarni Date: Mon, 25 Jul 2016 19:53:11 +0530 Message-ID: Subject: [PR71078] x / abs(x) -> copysign (1.0, x) To: Richard Biener , gcc Patches X-IsSubscribed: yes 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 test-case (included in patch). Bootstrap+test in progress on x86_64-unknown-linux-gnu. Thanks, Prathamesh diff --git a/gcc/match.pd b/gcc/match.pd index 21bf617..6c3d6ec 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -391,6 +391,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (mult (abs@1 @0) @1) (mult @0 @0)) +/* PR71078: x / abs(x) -> copysign (1.0, x) */ +(simplify + (rdiv:C (convert? @0) (convert1? (abs @0))) + (if (FLOAT_TYPE_P (type) + && ! HONOR_NANS (type) + && ! HONOR_INFINITIES (type)) + (switch + (if (type == float_type_node) + (BUILT_IN_COPYSIGNF { build_one_cst (type); } (convert @0))) + (if (type == double_type_node) + (BUILT_IN_COPYSIGN { build_one_cst (type); } (convert @0))) + (if (type == long_double_type_node) + (BUILT_IN_COPYSIGNL { build_one_cst (type); } (convert @0)))))) + /* cos(copysign(x, y)) -> cos(x). Similarly for cosh. */ (for coss (COS COSH) copysigns (COPYSIGN) 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" } } */