This is an archive of the discontinued LLVM Phabricator instance.

[LoopFlatten] Run it earlier, just before IndVarSimplify
ClosedPublic

Authored by SjoerdMeijer on Oct 29 2020, 8:40 AM.

Details

Summary

This is a prep step for widening induction variables of a nested loop in LoopFlatten if this is posssible, to avoid having to perform certain overflow checks. Since IndVarSimplify may already widen induction variables, we want to run LoopFlatten just before IndVarSimplify. This is a minor reshuffle as both passes were already close after each other.

This is separated out from D88880, which is about making LoopFlatten triggeron 64-bit targets too and is the motivation of this work.

PS. No pipeline pass manager test were changed, because LoopFlatten isn't enabled by default yet.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Oct 29 2020, 8:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2020, 8:40 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
SjoerdMeijer requested review of this revision.Oct 29 2020, 8:40 AM

Quick question on loop flattening preserving analyses. As far as I understand loop passes are required to preserve a number of analyses across all loops. Although I'm not sure if that is new or old pass managers. It's because function level analyses can't easily be rerun inside loop passes.

Would that be true for loop flattening? If we did enable this, would the pass pipeline still look OK?

Quick question on loop flattening preserving analyses. As far as I understand loop passes are required to preserve a number of analyses across all loops. Although I'm not sure if that is new or old pass managers. It's because function level analyses can't easily be rerun inside loop passes.

Would that be true for loop flattening? If we did enable this, would the pass pipeline still look OK?

From a look at the relevant parts in LoopFlatten, I think it's the NPM that deals with the preserved analysis business:

https://github.com/llvm/llvm-project/blob/b51b424c679f57dd65d83652f3e62ac2cf6de738/llvm/lib/Transforms/Scalar/LoopFlatten.cpp#L550

And what I really hope is that a Loop pass is allowed to modify a loop, and that the pass managers is providing the framework to rerun loop analysis if loop flatten returns getLoopPassPreservedAnalyses() and a next pass depends on loop info.

But fair enough, that's a bit of speculation as I never had to look into this. Since the NPM seems to deal with this, I am further guessing it might be the LPM. However, since this is a minor reshuffle, any problem that we had before, is one we will currently have....and since I haven't seen problems, I am guessing (again) it is alright, but could look into this....

I have found this so far:

A LoopPass subclass which is intended to run as part of the main loop pass pipeline needs to preserve all of the same function analyses that the other loop passes in its pipeline require.

which mentions function analysis, so looks okay to me.

OK yeah, they look like they are already in different loop managers on the old pass manager side.

llvm/lib/Passes/PassBuilder.cpp
540

I think this one would be better put into a new LoopPassManager, LPM3, if flattening is enabled. I think that's how it's meant to work.

SjoerdMeijer added inline comments.Nov 5 2020, 6:27 AM
llvm/lib/Passes/PassBuilder.cpp
540

Cheers Dave. Like we discussed, I will convert LoopFlatten first to a Function pass as a loop pass that's deleting loops might be a bit tricky; looks like that is just the easiest to deal with this. Then, I will return to this change.

Rebased on top of D90940, which converts this into a function pass.

This revision is now accepted and ready to land.Nov 10 2020, 10:54 AM