From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61342 invoked by alias); 28 May 2015 12:34:44 -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 61260 invoked by uid 89); 28 May 2015 12:34:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 28 May 2015 12:34:41 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 466F919F27D for ; Thu, 28 May 2015 12:34:40 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-89.ams2.redhat.com [10.36.116.89]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4SCYcLr017560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 28 May 2015 08:34:39 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.9/8.14.9) with ESMTP id t4SCYbaC030948; Thu, 28 May 2015 14:34:37 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.9/8.14.9/Submit) id t4SCYa0S030946; Thu, 28 May 2015 14:34:36 +0200 Date: Thu, 28 May 2015 13:10:00 -0000 From: Jakub Jelinek To: Marek Polacek Cc: GCC Patches Subject: Re: [PATCH] Optimize (CST1 << A) == CST2 (PR tree-optimization/66299) Message-ID: <20150528123436.GM10247@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20150528121545.GE27320@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150528121545.GE27320@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg02633.txt.bz2 On Thu, May 28, 2015 at 02:15:45PM +0200, Marek Polacek wrote: > This PR points out that we weren't able to optimize 1 << x == 2 to just > x == 1. This is my attempt to fix that: if we see (CST1 << A) == CST2 > and CST2 is a multiple of CST1, use log2 to get rid of the shift, but > only if the result of the shift is a natural number (including zero). Is CST2 a multiple of CST1 the best test though? I mean say in (0x8001U << x) == 0x20000U 0x20000U isn't a multiple of 0x8001U, yet there is only one valid value of x for which it holds (17), so we could very well optimize that to x == 17. If popcount of the CST1 is 1, then multiple_of_p is supposedly sufficient (have you checked if CST1 is negative that it still works?), for others supposedly we could have a helper function that would just try in a loop all shift counts from 0 to precision - 1, and note when (CST1 << b) == CST2 - if for no b, then it should fold regardless of has_single_use to false or true, if for exactly one shift count, then use a comparison against that shift count, otherwise give up? Supposedly (CST1 >> A) == CST2 can be handled similarly. > If CST2 is not a multiple of CST1, then the whole expression can be > discarded, but I'd like to do that as a follow-up. > (It would help if our current match.pd grammar allowed us to use "else", > any plans on doing that?) Jakub