From e5dc57d4fb356db31476da8717f20e9f5dc58ac6 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Sat, 20 Oct 2012 20:45:01 +0000 Subject: [PATCH] Fix an infinite loop in the loop-vectorizer. PR14134. llvm-svn: 166379 --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 6 ++++++ .../Transforms/LoopVectorize/2012-10-20-infloop.ll | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 llvm/test/Transforms/LoopVectorize/2012-10-20-infloop.ll diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c11c66f1aeb5..027fe0656be5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1175,6 +1175,12 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi, bool FoundInBlockUser = false; // Did we reach the initial PHI node ? bool FoundStartPHI = false; + + // If the instruction has no users then this is a broken + // chain and can't be a reduction variable. + if (Iter->use_begin() == Iter->use_end()) + return false; + // For each of the *users* of iter. for (Value::use_iterator it = Iter->use_begin(), e = Iter->use_end(); it != e; ++it) { diff --git a/llvm/test/Transforms/LoopVectorize/2012-10-20-infloop.ll b/llvm/test/Transforms/LoopVectorize/2012-10-20-infloop.ll new file mode 100644 index 000000000000..16a77291995d --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/2012-10-20-infloop.ll @@ -0,0 +1,12 @@ +; RUN: opt < %s -loop-vectorize -dce + +; Check that we don't fall into an infinite loop. +define void @test() nounwind { +entry: + br label %for.body + +for.body: + %0 = phi i32 [ 1, %entry ], [ 0, %for.body ] + br label %for.body +} +