summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-02-13 10:02:52 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-02-13 10:02:52 +0000
commit1f95ef1815c9b6a961811ec78e44d14b277abdd3 (patch)
tree2879b175920dae8f95db19a9636f24bbfceb4834 /llvm
parent92e0bb5c9558bde77f8cb7a8d4b5e3d75070c7c7 (diff)
downloadbcm5719-llvm-1f95ef1815c9b6a961811ec78e44d14b277abdd3.tar.gz
bcm5719-llvm-1f95ef1815c9b6a961811ec78e44d14b277abdd3.zip
[LoopInterchange] Check number of latch successors before accessing them.
In cases where the OuterMostLoopLatchBI only has a single successor, accessing the second successor will fail. This fixes a failure when building the test-suite with loop-interchange enabled. Reviewers: mcrosier, karthikthecool, davide Reviewed by: karthikthecool Differential Revision: https://reviews.llvm.org/D42906 llvm-svn: 324994
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopInterchange.cpp2
-rw-r--r--llvm/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll40
2 files changed, 41 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 8540f5ae30c..4cda6ed4b87 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -541,7 +541,7 @@ struct LoopInterchange : public FunctionPass {
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
diff --git a/llvm/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll b/llvm/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll
new file mode 100644
index 00000000000..b17bbde45e7
--- /dev/null
+++ b/llvm/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
+
OpenPOWER on IntegriCloud