[PATCH] D42906: [LoopInterchange] Check number of latch successors before accessing them.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 02:06:28 PST 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324994: [LoopInterchange] Check number of latch successors before accessing them. (authored by fhahn, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42906?vs=132816&id=134009#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42906

Files:
  llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
  llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll


Index: llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
+++ llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -541,7 +541,7 @@
     BasicBlock *OuterMostLoopLatch = OuterMostLoop->getLoopLatch();
     BranchInst *OuterMostLoopLatchBI =
         dyn_cast<BranchInst>(OuterMostLoopLatch->getTerminator());
-    if (!OuterMostLoopLatchBI)
+    if (!OuterMostLoopLatchBI || OuterMostLoopLatchBI->getNumSuccessors() != 2)
       return false;
 
     // Since we currently do not handle LCSSA PHI's any failure in loop
Index: llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll
===================================================================
--- llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll
+++ llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -loop-interchange -S | FileCheck %s
+
+; BB latch1 is the loop latch, but does not exit the loop.
+define void @foo() {
+entry:
+  %dest = alloca i16*, align 8
+  br label %header1
+
+header1:
+  %0 = phi i16* [ %2, %latch1 ], [ undef, %entry ]
+  br i1 false, label %inner, label %loopexit
+
+inner:
+  br i1 undef, label %inner.ph, label %latch1
+
+inner.ph:
+  br label %inner.body
+
+inner.body:
+  %1 = load i16, i16* %0, align 2
+  store i16* inttoptr (i64 2 to i16*), i16** %dest, align 8
+  br i1 false, label %inner.body, label %inner.loopexit
+
+inner.loopexit:
+  br label %latch1
+
+latch1:
+  %2 = phi i16* [ %0, %inner ], [ undef, %inner.loopexit ]
+  br label %header1
+
+loopexit:                                         ; preds = %header1
+  unreachable
+}
+
+; CHECK-LABEL: inner.body:
+; CHECK: br i1 false, label %inner.body, label %inner.loopexit
+; CHECK: latch1:
+; CHECK-NEXT: %2 = phi i16* [ %0, %inner ], [ undef, %inner.loopexit ]
+; CHECK-NEXT: br label %header1
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42906.134009.patch
Type: text/x-patch
Size: 1974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/1ba9ba96/attachment.bin>


More information about the llvm-commits mailing list