From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4533 invoked by alias); 21 May 2011 12:24:25 -0000 Received: (qmail 4524 invoked by uid 22791); 21 May 2011 12:24:24 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 21 May 2011 12:24:09 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 29025) id F0B399AC7D4; Sat, 21 May 2011 14:24:07 +0200 (CEST) Date: Sat, 21 May 2011 18:54:00 -0000 From: Zdenek Dvorak To: Tom de Vries Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH PR45098, 7/10] Nowrap limits iterations Message-ID: <20110521122407.GA22860@kam.mff.cuni.cz> References: <4DD21F6E.4050308@codesourcery.com> <4DD221CF.4040002@codesourcery.com> <4DD3FD79.2020804@codesourcery.com> <20110518211157.GA19788@kam.mff.cuni.cz> <4DD63AE1.7070600@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DD63AE1.7070600@codesourcery.com> User-Agent: Mutt/1.5.18 (2008-05-17) 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 X-SW-Source: 2011-05/txt/msg01530.txt.bz2 Hi, > > Would it be possible to add the handling of these cases > > to estimate_numbers_of_iterations, rather than doing it just for ivopts? > > Yes, I did that now. > > Thanks, > - Tom > > 2011-05-05 Tom de Vries > > PR target/45098 > * tree-ssa-loop-niter.c (infer_loop_bounds_from_pointer_arith): New > function. > (infer_loop_bounds_from_undefined): Use new function. this is OK. > * tree-ssa-loop-ivopts.c (may_eliminate_iv): Fix > estimated_loop_iterations comparison. I don't think this part is correct, though: > Index: gcc/tree-ssa-loop-ivopts.c > =================================================================== > --- gcc/tree-ssa-loop-ivopts.c (revision 173734) > +++ gcc/tree-ssa-loop-ivopts.c (working copy) > @@ -4391,8 +4391,13 @@ may_eliminate_iv (struct ivopts_data *da > { > if (!estimated_loop_iterations (loop, true, &max_niter)) > return false; > - /* The loop bound is already adjusted by adding 1. */ > - if (double_int_ucmp (max_niter, period_value) > 0) > + /* The max iterations applies also to the number of times the loop > + exit condition is executed. The number of distinct values of > + the cand is period_value + 1. So, test for > + 'period_value + 1 >= max_iterations'. > + */ > + period_value = double_int_add (period_value, double_int_one); > + if (double_int_ucmp (max_niter, period_value) > 0) > return false; > } > else max_niter is the upper bound on the number of iterations of the loop, i.e., the number of executions of its latch edge. Therefore, the control induction variable of the loop will (at the exit statement) achieve at most max_niter + 1 different values. Conversely, the number of distinct values that the control iv can represent is period + 1 (naming of the "period" variable is a bit missleading). Thus, the correct test is # of available values >= # of required values, equivalently period + 1 >= max_niter + 1, equivalently period >= max_niter, i.e., the current test. Zdenek