From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8060 invoked by alias); 25 Jun 2014 08:36:33 -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 8003 invoked by uid 89); 25 Jun 2014 08:36:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham 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; Wed, 25 Jun 2014 08:36:32 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5P8aQgV020218 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Jun 2014 04:36:29 -0400 Received: from tucnak.zalov.cz (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5P8aN56020645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 25 Jun 2014 04:36:25 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.8/8.14.7) with ESMTP id s5P8aLXJ028730; Wed, 25 Jun 2014 10:36:21 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.8/8.14.8/Submit) id s5P8aIfH028729; Wed, 25 Jun 2014 10:36:18 +0200 Date: Wed, 25 Jun 2014 08:36:00 -0000 From: Jakub Jelinek To: Kugan Cc: "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH 2/2] Enable elimination of zext/sext Message-ID: <20140625083618.GZ31640@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <53A9658F.2070304@linaro.org> <53A966BF.30806@linaro.org> <20140624122101.GX31640@tucnak.redhat.com> <53AA8501.809@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <53AA8501.809@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2014-06/txt/msg01982.txt.bz2 On Wed, Jun 25, 2014 at 06:14:57PM +1000, Kugan wrote: > For these flags, value ranges generated are not usable for extension > eliminations. Therefore, without this some of the test cases in > regression fails. For example: > > short a; > void > foo (void) > { > for (a = 0; a >= 0; a++) > ; > } > -Os -fno-strict-overflow produces the following range for the index > increment and hence goes into infinite loop. > _10: [1, 32768] > _10 = _4 + 1; For -fwrapv I don't see why you'd get into trouble ever, the VRP computation should be well aware of the -fwrapv semantics and the value ranges should reflect that. For -fno-strict-overflow, I have no idea since it is very weirdly defined. In any case, for your example above, the loop is always well defined, because for char/short a++ is performed as: a = (short) ((int) a + 1) So, if the patch turns it into infinite loop, with -Os -fno-strict-overflow or -Os, it is simply a problem with the patch. VR [1, 32768] looks correct, a++ is performed only if a is >= 0, therefore before addition [0, 32767]. But from VR [1, 32768] you can't optimize away the sign extension, make sure you don't have there off-by-one? It would be nice if the patch contained some testcases, it is easy to construct testcases where you have arbitrary VRs on some SSA_NAMEs, you just need something to stick the VR on, so you can do something like: type foo (type a) { if (a < VR_min + 1 || a > VR_max + 1) return; // If VR_min is type minimum or VR_max type maximum this needs to be adjusted of course. a = a + 1; // now you can try some cast that your optimization would try to optimize return a; } Or void bar (type a) { a = (a & mask) + bias; (or similarly) } Make sure to cover the boundary cases, where VR minimum or maximum still allow optimizing away zero and/or sign extensions, and another case where they are +- 1 and already don't allow it. Jakub