Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -483,7 +483,7 @@ /// Vectorize Load and Store instructions, optionally masking the vector /// operations if \p BlockInMask is non-null. - void vectorizeMemoryInstruction(Instruction *Instr, + void vectorizeMemoryInstruction(Instruction *Instr, Value *Ptr, bool InBounds, VectorParts *BlockInMask = nullptr); /// Set the debug location in the builder using the debug location in @@ -2342,6 +2342,7 @@ } void InnerLoopVectorizer::vectorizeMemoryInstruction(Instruction *Instr, + Value *Ptr, bool InBounds, VectorParts *BlockInMask) { // Attempt to issue a wide load. LoadInst *LI = dyn_cast(Instr); @@ -2358,7 +2359,6 @@ Type *ScalarDataTy = getMemInstValueType(Instr); Type *DataTy = VectorType::get(ScalarDataTy, VF); - Value *Ptr = getLoadStorePointerOperand(Instr); // An alignment of 0 means target abi alignment. We need to use the scalar's // target abi alignment in such a case. const DataLayout &DL = Instr->getModule()->getDataLayout(); @@ -2388,11 +2388,6 @@ if (isMaskRequired) Mask = *BlockInMask; - bool InBounds = false; - if (auto *gep = dyn_cast( - getLoadStorePointerOperand(Instr)->stripPointerCasts())) - InBounds = gep->isInBounds(); - const auto CreateVecPtr = [&](unsigned Part, Value *Ptr) -> Value * { // Calculate the pointer for the specific unroll-part. GetElementPtrInst *PartPtr = nullptr; @@ -7412,12 +7407,12 @@ void VPWidenMemoryInstructionRecipe::execute(VPTransformState &State) { VPValue *Mask = getMask(); if (!Mask) - return State.ILV->vectorizeMemoryInstruction(&Instr); + return State.ILV->vectorizeMemoryInstruction(&Instr, Ptr, InBounds); InnerLoopVectorizer::VectorParts MaskValues(State.UF); for (unsigned Part = 0; Part < State.UF; ++Part) MaskValues[Part] = State.get(Mask, Part); - State.ILV->vectorizeMemoryInstruction(&Instr, &MaskValues); + State.ILV->vectorizeMemoryInstruction(&Instr, Ptr, InBounds, &MaskValues); } static ScalarEpilogueLowering Index: llvm/lib/Transforms/Vectorize/VPlan.h =================================================================== --- llvm/lib/Transforms/Vectorize/VPlan.h +++ llvm/lib/Transforms/Vectorize/VPlan.h @@ -969,12 +969,17 @@ private: Instruction &Instr; std::unique_ptr User; + bool InBounds = false; + Value *Ptr; public: VPWidenMemoryInstructionRecipe(Instruction &Instr, VPValue *Mask) : VPRecipeBase(VPWidenMemoryInstructionSC), Instr(Instr) { if (Mask) // Create a VPInstruction to register as a user of the mask. User.reset(new VPUser({Mask})); + Ptr = getLoadStorePointerOperand(&Instr); + if (auto *GEP = dyn_cast(Ptr->stripPointerCasts())) + InBounds = GEP->isInBounds(); } /// Method to support type inquiry through isa, cast, and dyn_cast.