With loop peeling, it is important that unnecessary PHIs be avoided or
it will leads to spurious peeling. One source of such PHIs is loop
rotation which creates PHIs for invariant loads. Those PHIs are
particularly problematic since loop peeling is now run as part of simple
loop unrolling before GVN is run, and are thus a source of spurious
peeling.
Note that while some of the load can be hoisted and eventually
eliminated by instruction combine, this is not always possible due to
alignment issue. In particular, the motivating example [1] was a load
inside a class instance which cannot be hoisted because the `this'
pointer has an alignment of 1.
[1]
http://lists.llvm.org/pipermail/llvm-dev/attachments/20210312/4ce73c47/attachment.cpp
This commit adds logic during loop rotation to prevent PHIs creation for
invariant load, by relying on FindAvailableLoadedValue()'s analysis of
aliasing.
Why does this use FindAvailableLoadedValue if it isn't looking for available values? Can't you just use a loop over isNoModRef(AA->getModRefInfo(I, Loc))?