From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109684 invoked by alias); 24 Jul 2015 09:26:18 -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 109672 invoked by uid 89); 24 Jul 2015 09:26:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f178.google.com Received: from mail-ie0-f178.google.com (HELO mail-ie0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 24 Jul 2015 09:26:15 +0000 Received: by iehx8 with SMTP id x8so14087818ieh.3 for ; Fri, 24 Jul 2015 02:26:14 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.107.13.201 with SMTP id 192mr20589926ion.70.1437729974007; Fri, 24 Jul 2015 02:26:14 -0700 (PDT) Received: by 10.107.142.7 with HTTP; Fri, 24 Jul 2015 02:26:13 -0700 (PDT) In-Reply-To: References: <20150721093831.GF1780@tucnak.redhat.com> <0B875690-DCED-43AB-B964-67CDDCAF6776@gmail.com> <55B111CD.2030300@redhat.com> <20150723163329.GA27818@gate.crashing.org> <55B1D313.6010703@redhat.com> Date: Fri, 24 Jul 2015 09:31:00 -0000 Message-ID: Subject: Re: Fold some equal to and not equal to patterns in match.pd From: Richard Biener To: Kai Tietz Cc: Jeff Law , Segher Boessenkool , Andrew Pinski , Jakub Jelinek , "Hurugalawadi, Naveen" , "gcc-patches@gcc.gnu.org" Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg02029.txt.bz2 On Fri, Jul 24, 2015 at 9:48 AM, Kai Tietz wrote: > 2015-07-24 7:54 GMT+02:00 Jeff Law : >> On 07/23/2015 10:33 AM, Segher Boessenkool wrote: >>> >>> On Thu, Jul 23, 2015 at 10:09:49AM -0600, Jeff Law wrote: >>>> >>>> It seems to me in these kind of cases that selection of the canonical >>>> form should be driven by factors outside of which is better for a >>>> particular target. ie, which is simpler >>> >>> >>> I agree. But neither form is simpler here, and we need to have both >>> forms in other contexts, so there is no real benefit to canonicalising. >> >> >> >> a << N ==/!= 0 >> >> Looks like two operations. A shift and a comparison against zero regardless >> of whether or not N is constant. >> >> >> a&(-1>>N) ==/!= 0 >> >> For a varying N, this has a shift, logical and and comparison against zero. >> >> For a constant N obviously the shift collapses to a constant and we're left >> with two operations again. >> >> So for gimple, I'd prefer to see us using the a << N form. >> >> If we need both forms in other contexts, we ought to be looking to eliminate >> that need :-) >> >> If we go to the RTL level, then it's more complex -- it might depend on the >> constant produced by the -1 >> N operation, whether or not the target can >> shift by more than one bit at a time (H8/300 series is limited here for >> example), whether or not one operation sets condition codes in a useful way, >> potentially allowing the comparison to be removed, etc etc. rtx_costs, even >> with its limitations is probably the way to drive selection of form for the >> RTL optimizers. >> >> >> Jeff > > I fully agree. But there are case there is not necessarily a 'better' > representation. For example for sinking converts into shift-operation > can be tricky. > > for 'typea a;' > > (typeb) (a << N) -> ((typeb) a) << N > > 'bitsizeof (typeb) <= N' result is always zero. > 'bitsizeof (typeb) > N' result needs to be calculated. > > But it isn't necessarily easy to say if form '(typeb) (a << N)', or > '((typeb) a) << N' form is to be prefered. It strongly depends on > expression this pattern is used in. > > For RTL this pattern has another issue, as we need to take natural > mode into account here too, > > We should define for such forms our 'normal' representation. The usual reason for canonicalization is CSE. In this case you'd need to have X = a & (-1 >> N) == 0; Y = a << N == 0; and want to CSE Y. Might be not a very common pattern though. Richard. > Kai