From 787ad64b989937e0d79e176b0bf9af4a85a839d0 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Sun, 23 Jun 2013 19:38:56 +0000 Subject: [PATCH] SLP Vectorizer: Erase instructions outside the vectorizeTree method. The RAII builder location guard is saving a reference to instructions, so we can't erase instructions during vectorization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184671 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/SLPVectorizer.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4f378e3d600..838cb9599cb 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -848,6 +848,12 @@ bool FuncSLP::vectorizeStoreChain(ArrayRef Chain, int CostThreshold) { if (Cost < CostThreshold) { DEBUG(dbgs() << "SLP: Decided to vectorize cost=" << Cost << "\n"); vectorizeTree(Operands); + + // Remove the scalar stores. + for (int i = 0, e = VF; i < e; ++i) + cast(Operands[i])->eraseFromParent(); + + // Move to the next bundle. i += VF - 1; Changed = true; } @@ -865,6 +871,11 @@ bool FuncSLP::vectorizeStoreChain(ArrayRef Chain, int CostThreshold) { DEBUG(dbgs() << "SLP: Found store chain cost = " << Cost << " for size = " << ChainLen << "\n"); vectorizeTree(Chain); + + // Remove all of the scalar stores. + for (int i = 0, e = Chain.size(); i < e; ++i) + cast(Chain[i])->eraseFromParent(); + return true; } @@ -1100,9 +1111,6 @@ Value *FuncSLP::vectorizeTree_rec(ArrayRef VL) { Value *VecPtr = Builder.CreateBitCast(SI->getPointerOperand(), VecTy->getPointerTo()); Builder.CreateStore(VecValue, VecPtr)->setAlignment(Alignment); - - for (int i = 0, e = VL.size(); i < e; ++i) - cast(VL[i])->eraseFromParent(); return 0; } default: