]> granicus.if.org Git - llvm/commit
[LoopPred] Handle a subset of NE comparison based latches
authorPhilip Reames <listmail@philipreames.com>
Sat, 1 Jun 2019 00:31:58 +0000 (00:31 +0000)
committerPhilip Reames <listmail@philipreames.com>
Sat, 1 Jun 2019 00:31:58 +0000 (00:31 +0000)
commitf9207feee4cdeaae35aba6b0ffa0ceaa23b4138d
treeddbfa563093306dfac181309300828e07468280a
parent22f0ee179f0a27a56b349a6e0098096f08b777e8
[LoopPred] Handle a subset of NE comparison based latches

At the moment, LoopPredication completely bails out if it sees a latch of the form:
%cmp = icmp ne %iv, %N
br i1 %cmp, label %loop, label %exit
OR
%cmp = icmp ne %iv.next, %NPlus1
br i1 %cmp, label %loop, label %exit

This is unfortunate since this is exactly the form that LFTR likes to produce. So, go ahead and recognize simple cases where we can.

For pre-increment loops, we leverage the fact that LFTR likes canonical counters (i.e. those starting at zero) and a (presumed) range fact on RHS to discharge the check trivially.

For post-increment forms, the key insight is in remembering that LFTR had to insert a (N+1) for the RHS. CVP can hopefully prove that add nsw/nuw (if there's appropriate range on N to start with). This leaves us both with the post-inc IV and the RHS involving an nsw/nuw add, and SCEV can discharge that with no problem.

This does still need to be extended to handle non-one steps, or other harder patterns of variable (but range restricted) starting values. That'll come later.

Differential Revision: https://reviews.llvm.org/D62748

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362282 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/LoopPredication.cpp
test/Transforms/LoopPredication/basic.ll