From d10a2336a8e8934e8b7b31c1113efe0c6fb91db9 Mon Sep 17 00:00:00 2001 From: dim Date: Tue, 9 Dec 2014 07:34:28 +0000 Subject: Pull in r223171 from upstream llvm trunk (by Michael Zolotukhin): PR21302. Vectorize only bottom-tested loops. rdar://problem/18886083 This fixes a bug in the llvm vectorizer, which could sometimes cause vectorized loops to perform an additional iteration, leading to possible buffer overruns. Symptoms of this, which are usually segfaults, were first noticed when building gcc ports, here: https://lists.freebsd.org/pipermail/freebsd-ports/2014-September/095466.html https://lists.freebsd.org/pipermail/freebsd-toolchain/2014-September/001211.html Since this fix is very important for ports, bump __FreeBSD_version to make it easier for port maintainers to test whether the fix has been applied. Upstream PR: http://llvm.org/PR21302 MFC after: 3 days --- contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp') diff --git a/contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f9f6b18..6a9b9dc 100644 --- a/contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/contrib/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2864,6 +2864,14 @@ bool LoopVectorizationLegality::canVectorize() { if (!TheLoop->getExitingBlock()) return false; + // We only handle bottom-tested loops, i.e. loop in which the condition is + // checked at the end of each iteration. With that we can assume that all + // instructions in the loop are executed the same number of times. + if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) { + DEBUG(dbgs() << "LV: loop control flow is not understood by vectorizer\n"); + return false; + } + // We need to have a loop header. DEBUG(dbgs() << "LV: Found a loop: " << TheLoop->getHeader()->getName() << '\n'); -- cgit v1.1