[LLVMdev] A question about LICM (Loop Invariant Code Motion)

Chris Lattner clattner at apple.com
Wed Feb 9 17:38:22 PST 2011


On Feb 7, 2011, at 2:13 PM, Yuelu Duan wrote:

> Hi,
> 
> I recently looked into the LICM(Loop Invariant Code Motion) pass of
> LLVM and got a question about hoist load instruction to loop
> preheader. I would like to show two examples:
> 
> Example 1:
> int func(int n, int *fp) {
> int i;
> int a[1000];
> for (i = 0; i < n; ++i) {
>     a[i] += *fp; // load from *fp pointer, no hoist
> }
> }
> 
> Here, load *fp CAN NOT be hoisted to loop preheader. If replace *fp
> with an local pointer, the load can not be hoisted either.

clang -O2 hoists the load of fp out of the loop, since loop rotation transforms the loop.  Are you not seeing this?

-Chris



More information about the llvm-dev mailing list