This is an archive of the discontinued LLVM Phabricator instance.

[LoopFlatten] Mark loop analyses as perserved
ClosedPublic

Authored by nikic on Oct 7 2021, 11:41 AM.

Details

Summary

LoopFlatten does preserve loop analyses (DT, LI and SCEV), but currently doesn't mark them as preserved in the NewPM (the are marked as preserved in the LegacyPM). I think this doesn't really have an effect in the end because the loop pass adaptor will just assume they're preserved anyway, but let's be explicit about this for the sake of clarity.

Diff Detail

Event Timeline

nikic created this revision.Oct 7 2021, 11:41 AM
nikic requested review of this revision.Oct 7 2021, 11:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2021, 11:41 AM
aeubanks added inline comments.Oct 7 2021, 11:46 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
665

separately, this looks like it's not telling LPMUpdater that a loop has been deleted which is an issue

aeubanks accepted this revision.Oct 7 2021, 11:46 AM
This revision is now accepted and ready to land.Oct 7 2021, 11:46 AM
nikic added inline comments.Oct 7 2021, 11:48 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
665

I think this is actually fine, because this is a LoopNest pass, in which case LPMUpdater only has to be informed about the removal of top-level loops.

aeubanks added inline comments.Oct 7 2021, 11:53 AM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
665

If we delete a Loop, then allocate another Loop at the same address, we may fetch an invalid cached analysis later on. LPMUpdater::markLoopAsDeleted() clears cached analyses for that Loop.

nikic added inline comments.Oct 7 2021, 12:32 PM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
665

After looking a bit more closely, here's the problem:

However, as the pass doesn't control whether it gets used in LoopNestMode or not, this means that either you are forbidden from invalidating other loops (only LoopNest passes scheduled) or you are required to invalidate other loops (non-LoopNest passes scheduled as well). Something seems broken here.

Here's my test patch: https://gist.github.com/nikic/1a65b8cb384bb7e00084279255b93e65 It will currently assert for standalone uses of -loop-flatten because those use LoopNestMode.

This revision was automatically updated to reflect the committed changes.
nikic added inline comments.Oct 7 2021, 1:03 PM
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
665

I've put up D111350 to add the markLoopAsDeleted() call while relaxing the assertion in LPMUpdater.