diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index ee544b3a7f1..827c13ffc9f 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -284,7 +284,7 @@ void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr) { // If the src is an instruction that appeared earlier in the basic block // then it should already be vectorized. - if (SrcInst && SrcInst->getParent() == Instr->getParent()) { + if (SrcInst && OrigLoop->contains(SrcInst)) { assert(WidenMap.count(SrcInst) && "Source operand is unavailable"); // The parameter is a vector value from earlier. Params.push_back(WidenMap[SrcInst]); diff --git a/test/Transforms/LoopVectorize/scalar-store.ll b/test/Transforms/LoopVectorize/scalar-store.ll new file mode 100644 index 00000000000..5d207f94454 --- /dev/null +++ b/test/Transforms/LoopVectorize/scalar-store.ll @@ -0,0 +1,48 @@ +; RUN: opt < %s -loop-vectorize -force-vector-width=4 -dce -instcombine -licm -S -enable-if-conversion | FileCheck %s + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.9.0" + +; When we scalarize a store, make sure that the addresses are extracted +; from a vector. We had a bug where the addresses were the old scalar +; addresses. + +; CHECK: @foo +; CHECK: select +; CHECK: extractelement +; CHECK-NEXT: store +; CHECK: extractelement +; CHECK-NEXT: store +; CHECK: extractelement +; CHECK-NEXT: store +; CHECK: extractelement +; CHECK-NEXT: store +; CHECK: ret +define i32 @foo(i32* nocapture %a) nounwind uwtable ssp { + br label %1 + +;