From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4418 invoked by alias); 2 Apr 2006 16:04:52 -0000 Received: (qmail 4396 invoked by uid 48); 2 Apr 2006 16:04:50 -0000 Date: Sun, 02 Apr 2006 16:04:00 -0000 Message-ID: <20060402160450.4395.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/26900] Number of iterations not know for simple loop In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rakdver at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-04/txt/msg00097.txt.bz2 List-Id: ------- Comment #10 from rakdver at gcc dot gnu dot org 2006-04-02 16:04 ------- (In reply to comment #7) > Subject: Re: Number of iterations not know for simple loop > > > > I thought if we know that we are looking at the loop header copy condition that > > > we _know_ that the loop runs at least once, so we can avoid trying to prove > > > that again using fold. > > > > How? > > Sorry for the dumb question, I now understand what you mean. Let me > think about this for a moment, please. I think the basic idea is OK, although one needs to be a bit careful, at least with the following details: 1) Loops with multiple exits -- one would have to record the fact whether the condition was duplicated or not for each exit separately. 2) One would need to restrict this for "nice" induction variables; e.g., a loop like this one: int i, x, n; int a[10]; for (i = 0, x = -100; x < n; i++, x = (int) (unsigned char) x + 1) a[i] = x; becomes x = -100; i = 0; if (-100 < n) do { a[i] = x; i++; x = (int) (unsigned char) x + 1 } while (x < n) Now, the variable x in the compare x < n has evolution {156, +, 1} (the loop contains enough information to infer this, although we currently are not be able to do it), and we must check for n >= 156 in may_be_zero. >Maybe we should remember the BB of the loop header copy so we can verify >later that it still dominates the loop header. Checking that it still dominates the loop header should not be neccessary, just the fact that it was copied should matter. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26900