From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 107541 invoked by alias); 1 Oct 2015 14:51:31 -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 107528 invoked by uid 89); 1 Oct 2015 14:51:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: cam-smtp0.cambridge.arm.com Received: from fw-tnat.cambridge.arm.com (HELO cam-smtp0.cambridge.arm.com) (217.140.96.140) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 01 Oct 2015 14:51:30 +0000 Received: from arm.com (e106375-lin.cambridge.arm.com [10.2.206.46]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id t91EpQE9024268; Thu, 1 Oct 2015 15:51:26 +0100 Date: Thu, 01 Oct 2015 14:51:00 -0000 From: James Greenhalgh To: "pinskia@gmail.com" Cc: "gcc-patches@gcc.gnu.org" Subject: Re: [Patch match.pd] Add a simplify rule for x * copysign (1.0, y); Message-ID: <20151001145126.GA3881@arm.com> References: <1443707835-6888-1-git-send-email-james.greenhalgh@arm.com> <9593201B-9298-4529-A4DA-41B5DD6DCBFE@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9593201B-9298-4529-A4DA-41B5DD6DCBFE@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00081.txt.bz2 On Thu, Oct 01, 2015 at 03:28:22PM +0100, pinskia@gmail.com wrote: > > > > On Oct 1, 2015, at 6:57 AM, James Greenhalgh wrote: > > > > > > Hi, > > > > If it is cheap enough to treat a floating-point value as an integer and > > to do bitwise arithmetic on it (as it is for AArch64) we can rewrite: > > > > x * copysign (1.0, y) > > > > as: > > > > x ^ (y & (1 << sign_bit_position)) > > Why not just convert it to copysign (x, y) instead and let expand chose > the better implementation? Because that transformation is invalid :-) let x = -1.0, y = -1.0 x * copysign (1.0, y) = -1.0 * copysign (1.0, -1.0) = -1.0 * -1.0 = 1.0 copysign (x, y) = copysign (-1.0, -1.0) = -1.0 Or have I completely lost my maths skills :-) > Also I think this can only be done for finite and non trapping types. That may be well true, I swithered either way and went for no checks, but I'd happily go back on that and wrap this in something suitable restrictive if I need to. Thanks, James > > > > This patch implements that rewriting rule in match.pd, and a testcase > > expecting the transform. > > > > This is worth about 6% in 481.wrf for AArch64. I don't don't know enough > > about the x86 microarchitectures to know how productive this transformation > > is there. In Spec2006FP I didn't see any interesting results in either > > direction. Looking at code generation for the testcase I add, I think the > > x86 code generation looks worse, but I can't understand why it doesn't use > > a vector-side xor and load the mask vector-side. With that fixed up I think > > the code generation would look better - though as I say, I'm not an expert > > here... > > > > Bootstrapped on both aarch64-none-linux-gnu and x86_64 with no issues. > > > > OK for trunk? > > > > Thanks, > > James > > > > --- > > gcc/ > > > > 2015-10-01 James Greenhalgh > > > > * match.pd (mult (COPYSIGN:s real_onep @0) @1): New simplifier. > > > > gcc/testsuite/ > > > > 2015-10-01 James Greenhalgh > > > > * gcc.dg/tree-ssa/copysign.c: New. > > > > <0001-Patch-match.pd-Add-a-simplify-rule-for-x-copysign-1..patch> >