<br>When I compile to llvm (using -emit-llvm -O2 -S) the following piece of code:<br><br>int f(int *ptr, int incr, int n)<br>{<br> int r = n+1;<br><br> do<br> {<br> if(*ptr!=0)<br> r = n;<br> ptr += incr;<br>
n--;<br> } while(n!=0);<br> return r;<br>}<br><br>clang notices the index can be generated using a multiplication ( ptr[incr * loopindex] ) and generates some code which is at least as complicated (a multiplication is more or at least as complex as an addition + the generated code uses indirect addressing instead of direct addressing which is sometimes more complex). <br>
I am new to clang but I was thinking a compiler should do some strength reduction (and not the other way !).<br><br>Could you explain me why clang replaces this addition+direct addressing by a multiplication + indirect addressing ?<br>
<br> Thank you !<br><br> Damien<br>