This is an archive of the discontinued LLVM Phabricator instance.

[LoopRotate] Hoist invariant loads
AbandonedPublic

Authored by thopre on Mar 23 2021, 12:09 PM.

Details

Summary

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.

Diff Detail

Event Timeline

thopre created this revision.Mar 23 2021, 12:09 PM
thopre requested review of this revision.Mar 23 2021, 12:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 23 2021, 12:09 PM

Can you please give a less reduced test case, one with -O3, that exhibits said bad peeling before the patch?

nikic added inline comments.Mar 23 2021, 2:02 PM
llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
279

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))?

Currently we run LICM right after loop-rotate
What about running it either before, or before and after?

thopre abandoned this revision.Mar 24 2021, 5:06 AM

Drop in favor of better approach proposed by @lebedev.ri in D99249