From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30535 invoked by alias); 14 Jan 2015 09:24:53 -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 30523 invoked by uid 89); 14 Jan 2015 09:24:53 -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,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f170.google.com Received: from mail-ob0-f170.google.com (HELO mail-ob0-f170.google.com) (209.85.214.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 14 Jan 2015 09:24:51 +0000 Received: by mail-ob0-f170.google.com with SMTP id wp18so7075844obc.1 for ; Wed, 14 Jan 2015 01:24:49 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.60.114.40 with SMTP id jd8mr1855422oeb.12.1421227489526; Wed, 14 Jan 2015 01:24:49 -0800 (PST) Received: by 10.76.69.196 with HTTP; Wed, 14 Jan 2015 01:24:49 -0800 (PST) In-Reply-To: References: <877fwquwug.fsf@rasmusvillemoes.dk> Date: Wed, 14 Jan 2015 09:52:00 -0000 Message-ID: Subject: Re: RFC: Two minor optimization patterns From: Richard Biener To: Andrew Pinski Cc: Rasmus Villemoes , GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00989.txt.bz2 On Tue, Jan 13, 2015 at 11:47 PM, Andrew Pinski wrote: > On Tue, Jan 13, 2015 at 2:41 PM, Rasmus Villemoes wrote: >> [My first attempt at submitting a patch for gcc, so please forgive me >> if I'm not following the right protocol.] > > There are a few things missing. For one, a testcase or two for the > added optimizations. > >> >> Sometimes rounding a variable to the next even integer is written x += x >> & 1. This usually means using an extra register (and hence at least an >> extra mov instruction) compared to the equivalent x = (x + 1) & ~1. The >> first pattern below tries to do this transformation. >> >> While playing with various ways of rounding down, I noticed that gcc >> already optimizes all of x-(x&3), x^(x&3) and x&~(x&3) to simply >> x&~3. Does it also handle x+(x&3)? Where does it handle x - (x&3)? That is, doesn't the pattern also work for constants other than 1? Please put it before the abs simplifications after the last one handing bit_and/bit_ior. Thanks, Richard. > In fact, x&~(x&y) is rewritten as x&~y. However, the dual of this >> is not handled, so I included the second pattern below. >> >> I've tested the below in the sense that gcc compiles and that trivial >> test cases get compiled as expected. > > The other thing you missed is a changelog entry for the change you did. > Also you mentioned you tested the patch below but did not mention > which target you tested it on and you should run the full GCC > testsuite. > https://gcc.gnu.org/contribute.html is a good page to start with how > to handle most of the items above. > https://gcc.gnu.org/wiki/HowToPrepareATestcase is a good page on how > to write the testcase for testing the added optimization. > > Thanks, > Andrew Pinski > >> >> Rasmus >> >> >> >> diff --git gcc/match.pd gcc/match.pd >> index 81c4ee6..04a0bc4 100644 >> --- gcc/match.pd >> +++ gcc/match.pd >> @@ -262,6 +262,16 @@ along with GCC; see the file COPYING3. If not see >> (abs tree_expr_nonnegative_p@0) >> @0) >> >> +/* x + (x & 1) -> (x + 1) & ~1 */ >> +(simplify >> + (plus @0 (bit_and @0 integer_onep@1)) >> + (bit_and (plus @0 @1) (bit_not @1))) >> + >> +/* x | ~(x | y) -> x | ~y */ >> +(simplify >> + (bit_ior @0 (bit_not (bit_ior @0 @1))) >> + (bit_ior @0 (bit_not @1))) >> + >> >> /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST)) >> when profitable.