no Loop Invariant Motion?

Tim Prince n8tm@aol.com
Sun Jan 3 14:01:00 GMT 2010


prashant rawat wrote:
> I have a simple C code :
> 
> #include<stdio.h>
> int *c;
> int main ()
> {
>         int a=0, b;
>         while (a < 100)
>         {
>                         b = 10;
>                         a = a + 1;
>         }
>         c = &b;
>         printf ("%d\n", *c);
>         return 0;
> }
> 
> I would basically expect the b = 10 statement to be moved out of the
> while loop, as it is an invariant.
> However, it does not seem to happen in the *.lim dump file.
> I am using gcc 4.4.2 to compile, and the cmd line options are
> install/bin/gcc -fdump-tree-all -O3 filename.c

With gcc 4.5, the b assignment is moved out of the loop at -O, and the 
loop is removed entirely at -O3 or -Os.



More information about the Gcc-help mailing list