From bb950854acbb5966875763eaae7ab58e48e4f5a9 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Sun, 21 Oct 2012 06:49:10 +0000 Subject: Fix a bug in the vectorization of wide load/store operations. We used a SCEV to detect that A[X] is consecutive. We assumed that X was the induction variable. But X can be any expression that uses the induction for example: X = i + 2; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166388 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/LoopVectorize.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/Transforms/Vectorize/LoopVectorize.cpp') diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index 5a79c33bdc..1b6011bd1a 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -740,10 +740,15 @@ SingleBlockLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) { break; } + // The last index does not have to be the induction. It can be + // consecutive and be a function of the index. For example A[I+1]; + unsigned NumOperands = Gep->getNumOperands(); + Value *LastIndex = getVectorValue(Gep->getOperand(NumOperands -1)); + LastIndex = Builder.CreateExtractElement(LastIndex, Builder.getInt32(0)); + // Create the new GEP with the new induction variable. GetElementPtrInst *Gep2 = cast(Gep->clone()); - unsigned NumOperands = Gep->getNumOperands(); - Gep2->setOperand(NumOperands - 1, Induction); + Gep2->setOperand(NumOperands - 1, LastIndex); Ptr = Builder.Insert(Gep2); Ptr = Builder.CreateBitCast(Ptr, StTy->getPointerTo()); Value *Val = getVectorValue(SI->getValueOperand()); @@ -764,10 +769,15 @@ SingleBlockLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) { break; } + // The last index does not have to be the induction. It can be + // consecutive and be a function of the index. For example A[I+1]; + unsigned NumOperands = Gep->getNumOperands(); + Value *LastIndex = getVectorValue(Gep->getOperand(NumOperands -1)); + LastIndex = Builder.CreateExtractElement(LastIndex, Builder.getInt32(0)); + // Create the new GEP with the new induction variable. GetElementPtrInst *Gep2 = cast(Gep->clone()); - unsigned NumOperands = Gep->getNumOperands(); - Gep2->setOperand(NumOperands - 1, Induction); + Gep2->setOperand(NumOperands - 1, LastIndex); Ptr = Builder.Insert(Gep2); Ptr = Builder.CreateBitCast(Ptr, RetTy->getPointerTo()); LI = Builder.CreateLoad(Ptr); -- cgit v1.2.3-18-g5258