This is an archive of the discontinued LLVM Phabricator instance.

[LoopInterchange] Fix phi node ordering miscompile.
ClosedPublic

Authored by dmgreen on Oct 9 2017, 3:27 AM.

Details

Summary

It appears that the way that splitInnerLoopHeader splits blocks requires that the induction PHI will be the first PHI in the inner loop header. This makes sure that is actually the case when there are both IV and reduction phis.

Diff Detail

Event Timeline

dmgreen created this revision.Oct 9 2017, 3:27 AM
fhahn added a subscriber: fhahn.Oct 10 2017, 5:31 AM
fhahn added inline comments.
test/Transforms/LoopInterchange/phi-ordering.ll
15

Could you add a few more checks, making sure the loop structure is what we expect?

dmgreen updated this revision to Diff 119073.EditedOct 15 2017, 4:28 AM

Hello.

Good suggestion, I've updated the test.

test/Transforms/LoopInterchange/phi-ordering.ll
15

This depends on what we expect the loop structure to be :)

I originally had this compiling on thumbv6m, where the interchange here is almost certainly going to end up making things slower. The load/store to c would no longer be able to be pulled out of the inner loop. Hence the weak test check that would work even if the performance model here was fixes, and the interchange no longer done.

I've changed this test to v7a where I think vectorisation will make this interchange profitable, and added the loop structure checks you suggested.

Can you not pass the -loop-interchange-threshold option to force the cost model to always interchange? If this isn't possible with the current code then it seems like a major oversight.

fhahn accepted this revision.Oct 16 2017, 6:30 AM

LGTM, this is looks like a reasonable fix addressing a FIXME. Please use -loop-interchange-threshold in the test as suggested by @aemerson to ensure the test is always interchanged and hold off committing for a day or so, to give people in other timezones a chance to raise objections.

lib/Transforms/Scalar/LoopInterchange.cpp
1219

It might be helpful to keep a comment documenting the need for the induction phi to be the first PHI node here (without the FIXME of course)

This revision is now accepted and ready to land.Oct 16 2017, 6:30 AM
dmgreen updated this revision to Diff 119369.Oct 17 2017, 12:25 PM

I've updated the test to one that will always be profitable to interchange, as the vectoriser can then kick in.

lib/Transforms/Scalar/LoopInterchange.cpp
1219

Good idea.

This revision was automatically updated to reflect the committed changes.