[PATCH] D32261: [LoopUnroll] Don't try to unroll non-rotated loops
Davide Italiano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 19 17:19:08 PDT 2017
davide created this revision.
LoopUnroll doesn't seem to be in a state to handle this, and we end discovering later, when we end up with a broken dominator :(
(see https://bugs.llvm.org/show_bug.cgi?id=28103#c3)
Fixes PR28103.
https://reviews.llvm.org/D32261
Files:
lib/Transforms/Utils/LoopUnroll.cpp
test/Transforms/LoopUnroll/not-rotated.ll
Index: test/Transforms/LoopUnroll/not-rotated.ll
===================================================================
--- /dev/null
+++ test/Transforms/LoopUnroll/not-rotated.ll
@@ -0,0 +1,21 @@
+; RUN: opt -loop-unroll -verify-dom-info %s
+; REQUIRE: asserts
+
+define void @tinkywinky() {
+entry:
+ br label %header1
+header1:
+ %indvars.iv = phi i64 [ 1, %body2 ], [ 0, %entry ]
+ %exitcond = icmp ne i64 %indvars.iv, 1
+ br i1 %exitcond, label %body1, label %exit
+body1:
+ br i1 true, label %body2, label %sink
+body2:
+ br i1 true, label %header1, label %body3
+body3:
+ br label %sink
+sink:
+ br label %body2
+exit:
+ ret void
+}
Index: lib/Transforms/Utils/LoopUnroll.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnroll.cpp
+++ lib/Transforms/Utils/LoopUnroll.cpp
@@ -335,6 +335,17 @@
return false;
}
+ // If the loop is not rotated the latch is not one of the exiting blocks.
+ // Bail out on non-rotated loops.
+ SmallVector<BasicBlock *, 8> ExitingBlocks;
+ L->getExitingBlocks(ExitingBlocks);
+ bool NotRotated =
+ llvm::all_of(ExitingBlocks, [&LatchBlock](const BasicBlock *BB) {
+ return LatchBlock != BB;
+ });
+ if (NotRotated)
+ return false;
+
if (TripCount != 0)
DEBUG(dbgs() << " Trip Count = " << TripCount << "\n");
if (TripMultiple != 1)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32261.95861.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170420/c17347b8/attachment.bin>
More information about the llvm-commits
mailing list