This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnroll] Clamp unroll count to MaxTripCount
ClosedPublic

Authored by nikic on Jun 5 2021, 2:47 AM.

Details

Summary

Unrolling with more iterations than MaxTripCount is pointless, as those iterations can never be executed. As such, we clamp ULO.Count to MaxTripCount if it is known. This means we no longer need to consider iterations after MaxTripCount for exit folding, and the CompletelyUnroll flag becomes independent of ULO.TripCount.

Diff Detail

Event Timeline

nikic created this revision.Jun 5 2021, 2:47 AM
nikic requested review of this revision.Jun 5 2021, 2:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2021, 2:47 AM
efriedma added inline comments.
llvm/test/Transforms/LoopUnroll/multiple-exits.ll
6

Remove TODO?

llvm/test/Transforms/LoopUnroll/nonlatchcondbr.ll
161

Is this still testing what it's supposed to?

reames accepted this revision.Jun 7 2021, 10:40 AM

LGTM w/one required change.

llvm/lib/Transforms/Utils/LoopUnroll.cpp
735

Please add back the j != ExactTripCount bit.

I don't have a firm counter example, but the mixture of exitBI specific exact counts and loop maximum counts makes me nervous here.

This revision is now accepted and ready to land.Jun 7 2021, 10:40 AM
nikic marked 2 inline comments as done.Jun 7 2021, 12:04 PM
nikic added inline comments.
llvm/test/Transforms/LoopUnroll/nonlatchcondbr.ll
161

I think so. Based on commit history, this is just a positive test that unrolling happens with a non-exiting latch. It still happens, but makes use of the fact that it's a complete unroll now.

This revision was automatically updated to reflect the committed changes.