This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] Run LICM for nested unswitching tests.
ClosedPublic

Authored by fhahn on Apr 22 2022, 5:06 AM.

Details

Summary

When enabling freeze-loop-unswitch-cond the inserted freeze instruction
may block unswitching of parent loops if they get inserted in a block in
the parent loop (as the llvm::Loop-based invariance check only checks
whether an instruction is in a loop block or not).

In the optimization pipeline, LICM is responsible to hoist out loop
invariant instructions to enable further unswitching. Also run LICM for
nested unswitching tests in preparation for flipping the default of
freeze-loop-unswitch-cond.

Diff Detail

Event Timeline

fhahn created this revision.Apr 22 2022, 5:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 5:07 AM
fhahn requested review of this revision.Apr 22 2022, 5:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 5:07 AM
nikic accepted this revision.Apr 22 2022, 5:30 AM

LG, but maybe add a brief comment in the tests for why LICM is run?

This revision is now accepted and ready to land.Apr 22 2022, 5:30 AM

+ 1 to please clarify in the test why this is necessary.
Without the context, the question will be: why not generate the IR after LICM and only test SLU? Clarify the test needs the sequence SLU on inner loop, licm to hoist freeze condition and then SLU on outer loop can be done.

As a side note, the fact the freeze instruction needs licm and simple loop unswitch interleaved, will likely affect the plan we had around splitting off the non-trivial unswitch functionality into a separate function pass (the context for that is regarding using divergence analysis: https://reviews.llvm.org/D109762)
It seems like tracking the added freeze instructions and including the functionality of hoisting them as part of the "new" non-trivial SLU pass will resolve this, but I'd like to hear folks feedback on this.

fhahn added a comment.Apr 22 2022, 1:23 PM

As a side note, the fact the freeze instruction needs licm and simple loop unswitch interleaved, will likely affect the plan we had around splitting off the non-trivial unswitch functionality into a separate function pass (the context for that is regarding using divergence analysis: https://reviews.llvm.org/D109762)
It seems like tracking the added freeze instructions and including the functionality of hoisting them as part of the "new" non-trivial SLU pass will resolve this, but I'd like to hear folks feedback on this.

We could either hoist the freeze instructions or generate them at a place where no hoisting is required. At least as things are at the moment, I am not sure if it is worth it though, as it is just for testing in cases with nested loops that get unswitched from the inside out. Note that we don't only have this problem with freeze instructions we generate but potentially also with AND/ORs we generate when we have multiple invariant conditions.

This revision was landed with ongoing or failed builds.Apr 25 2022, 4:49 AM
This revision was automatically updated to reflect the committed changes.