This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Don't push operation across loop phi
ClosedPublic

Authored by nikic on Jun 10 2022, 7:26 AM.

Details

Summary

When pushing an operation across a phi node, we should avoid doing so across a loop backedge. This is generally non-profitable, because it does not reduce the number of times the operation is executed, and could lead to an infinite combine loop.

The code was already guarding against this, but using an insufficiently strong condition, which did not cover the case where the operation was originally outside the loop (in which case the transform moves the operation from outside the loop into the loop, which is particularly undesirable).

Diff Detail

Event Timeline

nikic created this revision.Jun 10 2022, 7:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 7:26 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Jun 10 2022, 7:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2022, 7:26 AM
spatel accepted this revision.Jun 10 2022, 8:17 AM

LGTM - thanks!

Note: I think we should still do the narrowing transform that I suggested in D123408, but that's independent of this fix. That narrowing commit ran into its own infinite loop due to a conflict matching constant expressions, but I can fix that.

This revision is now accepted and ready to land.Jun 10 2022, 8:17 AM
This revision was landed with ongoing or failed builds.Jun 13 2022, 1:49 AM
This revision was automatically updated to reflect the committed changes.