llvm.org GIT mirror llvm / d06ee0e
[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 Philip Reames 2 months ago
2 changed file(s) with 48 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
652652 RC.IV->getStepRecurrence(*SE)->isOne() &&
653653 SE->isKnownPredicate(ICmpInst::ICMP_ULE, RC.IV->getStart(), RC.Limit))
654654 RC.Pred = ICmpInst::ICMP_ULT;
655 if (RC.Pred == ICmpInst::ICMP_EQ &&
656 RC.IV->getStepRecurrence(*SE)->isOne() &&
657 SE->isKnownPredicate(ICmpInst::ICMP_ULE, RC.IV->getStart(), RC.Limit))
658 RC.Pred = ICmpInst::ICMP_UGE;
659
655660 }
656661
657662
17551755 ret i32 0
17561756 }
17571757
1758 ; Same as previous, except swapped br/cmp
1759 define i32 @eq_latch_dom_check_preinc(i32* %array, i32 %length, i32 %n) {
1760 ; CHECK-LABEL: @eq_latch_dom_check_preinc(
1761 ; CHECK-NEXT: entry:
1762 ; CHECK-NEXT: [[TMP5:%.*]] = icmp sle i32 [[N:%.*]], 0
1763 ; CHECK-NEXT: br i1 [[TMP5]], label [[EXIT:%.*]], label [[LOOP_PREHEADER:%.*]]
1764 ; CHECK: loop.preheader:
1765 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH:%.*]], -1
1766 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ule i32 [[N]], [[TMP0]]
1767 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 0, [[LENGTH]]
1768 ; CHECK-NEXT: [[TMP3:%.*]] = and i1 [[TMP2]], [[TMP1]]
1769 ; CHECK-NEXT: br label [[LOOP:%.*]]
1770 ; CHECK: loop:
1771 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 0, [[LOOP_PREHEADER]] ]
1772 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[TMP3]], i32 9) [ "deopt"() ]
1773 ; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
1774 ; CHECK-NEXT: [[DONE:%.*]] = icmp eq i32 [[I]], [[N]]
1775 ; CHECK-NEXT: br i1 [[DONE]], label [[EXIT_LOOPEXIT:%.*]], label [[LOOP]]
1776 ; CHECK: exit.loopexit:
1777 ; CHECK-NEXT: br label [[EXIT]]
1778 ; CHECK: exit:
1779 ; CHECK-NEXT: ret i32 0
1780 ;
1781 entry:
1782 %tmp5 = icmp sle i32 %n, 0
1783 br i1 %tmp5, label %exit, label %loop.preheader
1784
1785 loop.preheader:
1786 br label %loop
1787
1788 loop:
1789 %i = phi i32 [ %i.next, %loop ], [ 0, %loop.preheader ]
1790 %within.bounds = icmp ult i32 %i, %length
1791 call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1792
1793 %i.next = add nuw i32 %i, 1
1794 %done = icmp eq i32 %i, %n
1795 br i1 %done, label %exit, label %loop
1796
1797 exit:
1798 ret i32 0
1799 }
1800
17581801
17591802 ; NE latch - can't prove (end-start) mod step == 0 (i.e. might wrap
17601803 ; around several times or even be infinite)