[llvm] r324994 - [LoopInterchange] Check number of latch successors before accessing them.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 02:02:52 PST 2018
Author: fhahn
Date: Tue Feb 13 02:02:52 2018
New Revision: 324994
URL: http://llvm.org/viewvc/llvm-project?rev=324994&view=rev
Log:
[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
Added:
llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp?rev=324994&r1=324993&r2=324994&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopInterchange.cpp Tue Feb 13 02:02:52 2018
@@ -541,7 +541,7 @@ struct LoopInterchange : public Function
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
Added: llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll?rev=324994&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll (added)
+++ llvm/trunk/test/Transforms/LoopInterchange/interchange-latch-no-exit.ll Tue Feb 13 02:02:52 2018
@@ -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
+
More information about the llvm-commits
mailing list