Let's see an example with MemorySSA.
loop.header: ; 2 = MemoryPhi({entry,liveOnEntry},{loop.body,1}) %i.0 = phi i32 [ 0, %entry ], [ %inc, %loop.body ] ... loop.body: ; MemoryUse(2) MayAlias %0 = load i32**, i32*** @a, align 8, !tbaa !8 %idxprom = zext i32 %i.0 to i64 %arrayidx = getelementptr inbounds i32*, i32** %0, i64 %idxprom ; 1 = MemoryDef(2) store i32* null, i32** %arrayidx, align 8, !tbaa !8 ...
As you can see, there is a dependence with MayAlias between %0 = load of MemoryUse(2) and store of 1 = MemoryDef(2). However, it is WAR dependence at first iteration of the loop and there is no dependence at rest of iteration. In this case, we can hoist the '%0 = load` to preheader.
is !tbaa required here?
Also, would it be possible that @a contains the address of @a before we enter the loop? Could the first store in the loop modify @a that way?