Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit d06ee0e

Browse files
committed
[LoopPred] Extend LFTR normalization to the inverse EQ case
A while back, I added support for NE latches formed by LFTR. I didn't think that quite through, as LFTR will also produce the inverse EQ form for some loops and I hadn't handled that. This change just adds handling for that case as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365419 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d6c1421 commit d06ee0e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ static void normalizePredicate(ScalarEvolution *SE, Loop *L,
653653
RC.IV->getStepRecurrence(*SE)->isOne() &&
654654
SE->isKnownPredicate(ICmpInst::ICMP_ULE, RC.IV->getStart(), RC.Limit))
655655
RC.Pred = ICmpInst::ICMP_ULT;
656+
if (RC.Pred == ICmpInst::ICMP_EQ &&
657+
RC.IV->getStepRecurrence(*SE)->isOne() &&
658+
SE->isKnownPredicate(ICmpInst::ICMP_ULE, RC.IV->getStart(), RC.Limit))
659+
RC.Pred = ICmpInst::ICMP_UGE;
660+
656661
}
657662

658663

test/Transforms/LoopPredication/basic.ll

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,49 @@ exit:
17561756
ret i32 0
17571757
}
17581758

1759+
; Same as previous, except swapped br/cmp
1760+
define i32 @eq_latch_dom_check_preinc(i32* %array, i32 %length, i32 %n) {
1761+
; CHECK-LABEL: @eq_latch_dom_check_preinc(
1762+
; CHECK-NEXT: entry:
1763+
; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
1764+
; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1765+
; CHECK: loop.preheader:
1766+
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -1
1767+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ule i32 [[N]], [[TMP0]]
1768+
; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 0, [[LENGTH]]
1769+
; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
1770+
; CHECK-NEXT: br label [[LOOP:%.*]]
1771+
; CHECK: loop:
1772+
; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1773+
; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
1774+
; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
1775+
; CHECK-NEXT: [[DONE:%.*]] = icmp eq i32 [[I]], [[N]]
1776+
; CHECK-NEXT: br i1 [[DONE]], label [[EXIT_LOOPEXIT:%.*]], label [[LOOP]]
1777+
; CHECK: exit.loopexit:
1778+
; CHECK-NEXT: br label [[EXIT]]
1779+
; CHECK: exit:
1780+
; CHECK-NEXT: ret i32 0
1781+
;
1782+
entry:
1783+
%tmp5 = icmp sle i32 %n, 0
1784+
br i1 %tmp5, label %exit, label %loop.preheader
1785+
1786+
loop.preheader:
1787+
br label %loop
1788+
1789+
loop:
1790+
%i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1791+
%within.bounds = icmp ult i32 %i, %length
1792+
call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1793+
1794+
%i.next = add nuw i32 %i, 1
1795+
%done = icmp eq i32 %i, %n
1796+
br i1 %done, label %exit, label %loop
1797+
1798+
exit:
1799+
ret i32 0
1800+
}
1801+
17591802

17601803
; NE latch - can't prove (end-start) mod step == 0 (i.e. might wrap
17611804
; around several times or even be infinite)

0 commit comments

Comments
 (0)