This is an archive of the discontinued LLVM Phabricator instance.

[Loop Predication] Teach LP about reverse loops
ClosedPublic

Authored by anna on Nov 22 2017, 6:33 AM.

Details

Summary

Currently, we only support predication for forward loops with step
of 1. This patch enables loop predication for reverse or
countdownLoops, which satisfy the following conditions:

  1. The step of the IV is -1.
  2. The loop has a singe latch as B(X) = X <pred>

latchLimit with pred as s> or u>

  1. The IV of the guard is the decrement

IV of the latch condition (Guard is: G(X) = X-1 u< guardLimit).

This patch was downstream for a while and is the last series of patches
that's from our LP implementation downstream.

Diff Detail

Repository
rL LLVM

Event Timeline

anna created this revision.Nov 22 2017, 6:33 AM
fhahn added a subscriber: fhahn.Nov 22 2017, 9:13 AM
mkazantsev accepted this revision.Nov 27 2017, 12:37 AM

LGTM with test with %lowerlimit = 0 added.

lib/Transforms/Scalar/LoopPredication.cpp
534 ↗(On Diff #123931)

Can this go as a separate NFC? As far as I understand, we currently don't support steps of different types anyways.

545 ↗(On Diff #123931)

Assert that step is -1?

test/Transforms/LoopPredication/reverse.ll
21 ↗(On Diff #123931)

Do you mind adding a test with %lowerlimit = 0 to make sure that we don't predicate in this case?

This revision is now accepted and ready to land.Nov 27 2017, 12:37 AM
anna marked an inline comment as done.Nov 28 2017, 11:29 AM
anna added inline comments.
lib/Transforms/Scalar/LoopPredication.cpp
534 ↗(On Diff #123931)

yup.

test/Transforms/LoopPredication/reverse.ll
21 ↗(On Diff #123931)

Actually we will predicate in that case - this is the second (less known) benefit of loop predication - we know statically that the range check will deopt at some point during the iteration of loop, so now we will early deopt outside the loop.

See the test unsigned_reverse_loop_n_to_0.

This revision was automatically updated to reflect the committed changes.