From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100804 invoked by alias); 19 May 2016 18:42:20 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 100781 invoked by uid 89); 19 May 2016 18:42:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=HTo:D*ru, HTo:U*amonakov X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 19 May 2016 18:42:10 +0000 Received: from svr-orw-fem-04.mgc.mentorg.com ([147.34.97.41]) by relay1.mentorg.com with esmtp id 1b3StZ-0000hS-GN from Cesar_Philippidis@mentor.com ; Thu, 19 May 2016 11:42:05 -0700 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.3.224.2; Thu, 19 May 2016 11:42:04 -0700 Subject: Re: inhibit the sincos optimization when the target has sin and cos instructions To: Alexander Monakov References: <573628A1.1030501@codesourcery.com> <862033F1-A268-4236-B908-558C102199B5@gmail.com> <573B88B0.2080508@codesourcery.com> <573B8D84.4070908@codesourcery.com> <15446f73-b60a-c3f2-321e-80e0038785f1@acm.org> <573D3642.8080203@codesourcery.com> CC: Nathan Sidwell , Andrew Pinski , Richard Biener , "gcc-patches@gcc.gnu.org" From: Cesar Philippidis Message-ID: <573E08FC.4000605@codesourcery.com> Date: Thu, 19 May 2016 18:42:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------080307010305000002040604" X-SW-Source: 2016-05/txt/msg01556.txt.bz2 --------------080307010305000002040604 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Content-length: 1316 On 05/19/2016 04:29 AM, Alexander Monakov wrote: > On Wed, 18 May 2016, Cesar Philippidis wrote: > Note that the documentation suggests using 'make_safe_from' to concisely > express conflict resolution: > >> diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md >> index 33a4862..69bbb22 100644 >> --- a/gcc/config/nvptx/nvptx.md >> +++ b/gcc/config/nvptx/nvptx.md >> @@ -794,6 +794,24 @@ >> "" >> "%.\\tsqrt%#%t0\\t%0, %1;") >> >> +(define_expand "sincossf3" >> + [(set (match_operand:SF 0 "nvptx_register_operand" "=R") >> + (unspec:SF [(match_operand:SF 2 "nvptx_register_operand" "R")] >> + UNSPEC_COS)) >> + (set (match_operand:SF 1 "nvptx_register_operand" "=R") >> + (unspec:SF [(match_dup 2)] UNSPEC_SIN))] >> + "flag_unsafe_math_optimizations" > > ... here instead of special-casing the conflict case in curly braces you can > just write: > > "operands[2] = make_safe_from (operands[2], operands[0]);" > >> +{ >> + if (REGNO (operands[0]) == REGNO (operands[2])) >> + { >> + rtx tmp = gen_reg_rtx (GET_MODE (operands[2])); >> + emit_insn (gen_rtx_SET (tmp, operands[2])); >> + emit_insn (gen_sinsf2 (operands[1], tmp)); >> + emit_insn (gen_cossf2 (operands[0], tmp)); >> + DONE; >> + } >> +}) Done. Is this ok for trunk? Cesar --------------080307010305000002040604 Content-Type: text/x-patch; name="nvptx-sincos-20160519.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="nvptx-sincos-20160519.diff" Content-length: 1498 2016-05-19 Cesar Philippidis gcc/ * config/nvptx/nvptx.md (sincossf3): New pattern. gcc/testsuite/ * gcc.target/nvptx/sincos.c: New test. diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index 33a4862..1dd256d 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -794,6 +794,16 @@ "" "%.\\tsqrt%#%t0\\t%0, %1;") +(define_expand "sincossf3" + [(set (match_operand:SF 0 "nvptx_register_operand" "=R") + (unspec:SF [(match_operand:SF 2 "nvptx_register_operand" "R")] + UNSPEC_COS)) + (set (match_operand:SF 1 "nvptx_register_operand" "=R") + (unspec:SF [(match_dup 2)] UNSPEC_SIN))] + "flag_unsafe_math_optimizations" + "operands[2] = make_safe_from (operands[2], operands[0]);" +) + (define_insn "sinsf2" [(set (match_operand:SF 0 "nvptx_register_operand" "=R") (unspec:SF [(match_operand:SF 1 "nvptx_register_operand" "R")] diff --git a/gcc/testsuite/gcc.target/nvptx/sincos.c b/gcc/testsuite/gcc.target/nvptx/sincos.c new file mode 100644 index 0000000..921ec41 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/sincos.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ffast-math" } */ + +extern float sinf (float); +extern float cosf (float); + +float +sincos_add (float x) +{ + float s = sinf (x); + float c = cosf (x); + + return s + c; +} + +/* { dg-final { scan-assembler-times "sin.approx.f32" 1 } } */ +/* { dg-final { scan-assembler-times "cos.approx.f32" 1 } } */ --------------080307010305000002040604--