This is an archive of the discontinued LLVM Phabricator instance.

[LoopInterchange] Move PHI handling to adjustLoopBranches.
ClosedPublic

Authored by fhahn on Apr 27 2018, 10:27 AM.

Details

Summary

This patch moves the logic to handle reduction PHI nodes to the end of
adjustLoopBranches. Reduction PHI nodes in the outer loop header can be
moved to the inner loop header and reduction PHI nodes from the inner loop
header can be moved to the outer loop header. In the latter situation,
we have to deal with 1 kind of PHI nodes:

PHI nodes that are part of inner loop-only reductions.

We can replace the PHI node with the value coming from outside
the inner loop.

Diff Detail

Repository
rL LLVM

Event Timeline

fhahn added a comment.May 21 2018, 9:48 AM

ping. This is a refactoring to enable D43245 (interchanging loops with reductions)

efriedma added inline comments.Jun 15 2018, 12:32 PM
lib/Transforms/Scalar/LoopInterchange.cpp
1467 ↗(On Diff #144367)

This isa<PHINode> check seems weird; do you care whether it's specifically a reduction PHI node?

fhahn added inline comments.Jun 17 2018, 10:20 AM
lib/Transforms/Scalar/LoopInterchange.cpp
1467 ↗(On Diff #144367)

Thanks Eli!

Yes I think it misses that case when there is an instruction between the outer loop reduction PHI and the corresponding PHI node in the inner loop. I think I can get rid of this check in this patch and add something to D43245, as D43245 also relaxes the restrictions to allow such nodes.

fhahn updated this revision to Diff 151722.Jun 18 2018, 8:59 AM
fhahn edited the summary of this revision. (Show Details)

Removed handling of reduction PHIs across outer and inner loops from this patch, as support for such will only be added in D43245

fhahn updated this revision to Diff 151727.Jun 18 2018, 9:05 AM

Fix comment.

fhahn marked an inline comment as done.Jun 18 2018, 9:10 AM
fhahn added inline comments.
lib/Transforms/Scalar/LoopInterchange.cpp
1467 ↗(On Diff #144367)

I've replaced the check with an assertion, as reductions in outer are not supported in this patch.

I moved the check to D43245 and added a comment with the reasoning behind it. For reductions across inner and outer loops, it looks like isReductionPHI expects the incoming value of a reduction PHI in the inner loop to be the reduction PHI node of the outer loop.

This revision is now accepted and ready to land.Jun 18 2018, 12:46 PM
This revision was automatically updated to reflect the committed changes.