[cfe-dev] Loop invariant and strength reduction
damien.llvm at gmail.com
Thu Feb 24 15:25:08 PST 2011
When I compile to llvm (using -emit-llvm -O2 -S) the following piece of
int f(int *ptr, int incr, int n)
int r = n+1;
r = n;
ptr += incr;
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).
I am new to clang but I was thinking a compiler should do some strength
reduction (and not the other way !).
Could you explain me why clang replaces this addition+direct addressing by a
multiplication + indirect addressing ?
Thank you !
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev