LLVM/Clang optimization issue -- optimizer fails to discover common loop variable

Apologies, there was a typo in my last message.

"The following output was generated by LLVM” in the third paragraph should have read "The following output was generated by GCC 5.3.0”.


Being technical on the “lack of optimisation” here, it is not that LLVM doesn’t identify the common loop variable, but the fact that it (probably misguidedly) removes the loop variable and uses multiple pointers instead.

You WOULD want:

for(i = 0; i < size; i++)

s[i] = t[i];

to be converted to:

stmp = s;

ttemp = t;

send = s+size;

while(stmp < send)

s++ = t++;

right? So the compiler should recognise these cases, and do the conversion, but only when it’s actually “better”.

Agreed, it looks like this result is the result of a loop variable optimization which made the resulting code more complex. So what’s the best way to track this down?