Thanks. But with GCC 4.4.2, I get the dump in .lim file as <bb 3>: # a_14 = PHI <a_3(4), 0(2)> b_lsm.36_1 = 10; a_3 = a_14 + 1; if (a_3 <= 99) goto <bb 4>; else goto <bb 5>; <bb 4>: goto <bb 3>; Clearly, b_lsm.36_1 = 10; is still in the loop. Does this mean that loop invariant motion is not performed at all in gcc 4.4.2? I am just confused as to why it isn't working in 4.4.2 version. On Sun, Jan 3, 2010 at 7:31 PM, Tim Prince <n8tm@xxxxxxx> wrote: > 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. > -- With Regards, Prashant SIngh Rawat MTech, CSE, IIT Bombay