This is an archive of the discontinued LLVM Phabricator instance.

[LoopUnroll] Do not peel loop if we also completely unroll.
Needs ReviewPublic

Authored by fhahn on May 17 2020, 5:59 AM.

Details

Summary

Currently we do not adjust ULO.Count after peeling. If we completely
unroll a loop, this means we will end up executing TripCount + PeelCount
number of iterations, instead of TripCount iterations.
There is no point in peeling, if we completely unroll a loop, so we can
just skip it. Alternatively we could adjust ULO.Count, but skipping
peeling should result in a bit less work.

When not completely unrolling a loop, we should be fine, as ULO.TripCount
and ULO.TripCountMultiple are adjusted already.

Fixes PR45939.

Note the adjustments in PR33437, which are due to not peeling in this
case.

Diff Detail

Event Timeline

fhahn created this revision.May 17 2020, 5:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2020, 5:59 AM
efriedma added inline comments.May 17 2020, 2:20 PM
llvm/lib/Transforms/Utils/LoopUnroll.cpp
406

This code looks like it needs to be reorganized. We probably shouldn't be doing math using the TripCount, then changing the TripCount before we actually use the results of that math.

Maybe it would be more clear overall to move the peelLoop call into tryToUnrollLoop(), instead of calling it from UnrollLoop.

liuz added a subscriber: liuz.Nov 9 2020, 5:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2022, 9:27 AM