This is an archive of the discontinued LLVM Phabricator instance.

[LoopPredication] Account for critical edges when inserting assumes. PR26496
ClosedPublic

Authored by mkazantsev on Feb 27 2023, 2:58 AM.

Details

Summary

Loop predication can insert assumes to preserve knowledge about some facts that
may otherwise be lost, because loop predication is a lossy transform. When a guard
is represented as branch by widenable condition, it should insert it in the guarded
block. However, if the guarded block has other predecessors than the guard block,
then the condition might not dominate it. Currently we generate invalid code here.

One possible fix here is to split critical edge and insert the assume there, but in this
case we had to modify CFG, which Loop Predication is not currently doing, and we
want to keep it that way.

The fix is to handle this case by inserting a Phi which takes Cond as input from the
guard block and true from any other blocks. This is valid in terms of IR and does
not introduce any new knowledge if we came from another block.

Diff Detail

Event Timeline

mkazantsev created this revision.Feb 27 2023, 2:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 2:58 AM
mkazantsev requested review of this revision.Feb 27 2023, 2:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2023, 2:58 AM
nikic accepted this revision.Feb 27 2023, 3:08 AM

LGTM based on your description, but I'm not really familiar with this pass.

This revision is now accepted and ready to land.Feb 27 2023, 3:08 AM
skatkov accepted this revision.Feb 27 2023, 3:10 AM
This revision was landed with ongoing or failed builds.Feb 27 2023, 3:26 AM
This revision was automatically updated to reflect the committed changes.