Why this loop is not optimised out?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've got a very simple c program which copies all elements from array A to
back to array A. For example,

int *A;
A = (int*)malloc(sizeof(int)*SIZE);
for( i = 0; i < SIZE; i++) {
  A[i] = A[i];
}
I was expecting this to be optimised out by the compiler and eventually
turned into a noop. However, by measuring the runtime of this loop and
looking at the assembly code, it seems that the element is indeed loaded
from memory into register and then stored back to the same memory location.
I have -O3 enabled. Can anyone explain to me why the c compiler does not
optimise it? Or am I missing something here?

Many thanks.
-- 
View this message in context: http://old.nabble.com/Why-this-loop-is-not-optimised-out--tp32602004p32602004.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux