This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Scev analysing number of loop iterations returns (2^32-1) instead of -1
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Tobias Grosser <grosser at fim dot uni-passau dot de>
- Cc: gcc at gcc dot gnu dot org, graphite <gcc-graphite at googlegroups dot com>, Sebastian Pop <sebpop at gmail dot com>
- Date: Wed, 7 Oct 2009 17:23:34 +0200
- Subject: Re: Scev analysing number of loop iterations returns (2^32-1) instead of -1
- References: <1254926239.52806.22.camel@tobilaptop> <16634_1254926527_4ACCA8BE_16634_56_1_84fc9c000910070742k26bf6418l58fc3b873744ff63@mail.gmail.com> <1254928609.52806.28.camel@tobilaptop>
On Wed, Oct 7, 2009 at 5:16 PM, Tobias Grosser
<grosser@fim.uni-passau.de> wrote:
> On Wed, 2009-10-07 at 16:42 +0200, Richard Guenther wrote:
>> On Wed, Oct 7, 2009 at 4:37 PM, Tobias Grosser
>> <grosser@fim.uni-passau.de> wrote:
>> > I try to analyse this code:
>> > ------------------------------------------------------
>> > int foo (int N)
>> > {
>> > ?int ftab[257];
>> > ?int i, j;
>> >
>> > ?for (i = 0; i < N ?- 7488645; i++)
>> > ? ?j = ftab [i];
>> >
>> > ?return j;
>> > }
>> > ------------------------------------------------------
>> >
>> > The number of iterations I get is:
>> >
>> > (unsigned int) N_5(D) + 0x0ffffffff
>> >
>> > However I expect it to be
>> >
>> > (unsigned int) N_5(D) + (-1)
>>
>> No, that would be (unsigned int) (N_5(D) + -1) instead.
>>
>> It's fold that canonicalizes this to the above form - you
>> simply have to deal with it (unsigned arithmetic, that is).
>
> OK. So I need to understand this better.
>
> E.g:
>
> int foo (int N)
> {
> ?int ftab[257];
> ?int i, j;
>
> ?for (i = 0; i < N ?- 50; i++)
> ? ?j = ftab [i];
>
> ?return j;
> }
>
> Number of latch executions: (unsigned int) N_5(D) + 0x0ffffffcd
>
> What happens if N == 5? I would expect the number of latch iterations to
> be 0 as i < 5 - 50 is always false. However using the upper expression I
> get something like
> 5 + 0x0ffffffcd == 0x0ffffffd2
> what is a lot bigger than 0.
It's undefined if N == 5 because the loop counter would overflow.
Richard.
> Thanks for your help
>
> Tobi
>
>
>
>