llvm.org GIT mirror llvm / 0e9b799
[LoopPred] Fix a bug in unconditional latch bailout introduced in r362284 This is a really silly bug that even a simple test w/an unconditional latch would have caught. I tried to guard against the case, but put it in the wrong if check. Oops. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362727 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 3 months ago
2 changed file(s) with 28 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
849849 }
850850
851851 auto *BI = dyn_cast(LoopLatch->getTerminator());
852 if (!BI) {
852 if (!BI || !BI->isConditional()) {
853853 LLVM_DEBUG(dbgs() << "Failed to match the latch terminator!\n");
854854 return None;
855855 }
859859 "One of the latch's destinations must be the header");
860860
861861 auto *ICI = dyn_cast(BI->getCondition());
862 if (!ICI || !BI->isConditional()) {
862 if (!ICI) {
863863 LLVM_DEBUG(dbgs() << "Failed to match the latch condition!\n");
864864 return None;
865865 }
18521852 ret i32 0
18531853 }
18541854
1855 ; Negative test, make sure we don't crash on unconditional latches
1856 ; TODO: there's no reason we shouldn't be able to predicate the
1857 ; condition for an statically infinite loop.
1858 define i32 @unconditional_latch(i32* %a, i32 %length) {
1859 ; CHECK-LABEL: @unconditional_latch(
1860 ; CHECK-NEXT: loop.preheader:
1861 ; CHECK-NEXT: br label [[LOOP:%.*]]
1862 ; CHECK: loop:
1863 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[I_NEXT:%.*]], [[LOOP]] ], [ 400, [[LOOP_PREHEADER:%.*]] ]
1864 ; CHECK-NEXT: [[WITHIN_BOUNDS:%.*]] = icmp ult i32 [[I]], [[LENGTH:%.*]]
1865 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[WITHIN_BOUNDS]], i32 9) [ "deopt"() ]
1866 ; CHECK-NEXT: store volatile i32 0, i32* [[A:%.*]]
1867 ; CHECK-NEXT: [[I_NEXT]] = add i32 [[I]], 1
1868 ; CHECK-NEXT: br label [[LOOP]]
1869 ;
1870 loop.preheader:
1871 br label %loop
1872
1873 loop:
1874 %i = phi i32 [ %i.next, %loop ], [ 400, %loop.preheader ]
1875 %within.bounds = icmp ult i32 %i, %length
1876 call void (i1, ...) @llvm.experimental.guard(i1 %within.bounds, i32 9) [ "deopt"() ]
1877 store volatile i32 0, i32* %a
1878 %i.next = add i32 %i, 1
1879 br label %loop
1880 }