diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8827,11 +8827,10 @@ } void VPWidenMemoryInstructionRecipe::execute(VPTransformState &State) { - Instruction *Instr = getUnderlyingInstr(); - VPValue *StoredValue = isa(Instr) ? getStoredValue() : nullptr; - State.ILV->vectorizeMemoryInstruction(Instr, State, - StoredValue ? nullptr : this, getAddr(), - StoredValue, getMask()); + VPValue *StoredValue = isStore() ? getStoredValue() : nullptr; + State.ILV->vectorizeMemoryInstruction(&Ingredient, State, + StoredValue ? nullptr : toVPValue(), + getAddr(), StoredValue, getMask()); } // Determine how to lower the scalar epilogue, which depends on 1) optimising diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1265,8 +1265,9 @@ /// TODO: We currently execute only per-part unless a specific instance is /// provided. class VPWidenMemoryInstructionRecipe : public VPRecipeBase, - public VPValue, + public VPDef, public VPUser { + Instruction &Ingredient; void setMask(VPValue *Mask) { if (!Mask) @@ -1280,16 +1281,16 @@ public: VPWidenMemoryInstructionRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask) - : VPRecipeBase(VPWidenMemoryInstructionSC), - VPValue(VPValue::VPVMemoryInstructionSC, &Load), VPUser({Addr}) { + : VPRecipeBase(VPWidenMemoryInstructionSC), VPUser({Addr}), + Ingredient(Load) { + new VPValue(VPValue::VPVMemoryInstructionSC, &Load, this); setMask(Mask); } VPWidenMemoryInstructionRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredValue, VPValue *Mask) - : VPRecipeBase(VPWidenMemoryInstructionSC), - VPValue(VPValue::VPVMemoryInstructionSC, &Store), - VPUser({Addr, StoredValue}) { + : VPRecipeBase(VPWidenMemoryInstructionSC), VPUser({Addr, StoredValue}), + Ingredient(Store) { setMask(Mask); } @@ -1311,7 +1312,7 @@ } /// Returns true if this recipe is a store. - bool isStore() const { return isa(getUnderlyingInstr()); } + bool isStore() const { return isa(Ingredient); } /// Return the address accessed by this recipe. VPValue *getStoredValue() const { diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -124,8 +124,12 @@ return V; if (auto *V = dyn_cast(this)) return V; - if (auto *V = dyn_cast(this)) - return V; + if (auto *V = dyn_cast(this)) { + if (!V->isStore()) + return V->getVPValue(); + else + return nullptr; + } if (auto *V = dyn_cast(this)) return V; if (auto *V = dyn_cast(this)) @@ -144,8 +148,12 @@ return V; if (auto *V = dyn_cast(this)) return V; - if (auto *V = dyn_cast(this)) - return V; + if (auto *V = dyn_cast(this)) { + if (!V->isStore()) + return V->getVPValue(); + else + return nullptr; + } if (auto *V = dyn_cast(this)) return V; if (auto *V = dyn_cast(this)) @@ -993,10 +1001,10 @@ O << "\"WIDEN "; if (!isStore()) { - printAsOperand(O, SlotTracker); + getVPValue()->printAsOperand(O, SlotTracker); O << " = "; } - O << Instruction::getOpcodeName(getUnderlyingInstr()->getOpcode()) << " "; + O << Instruction::getOpcodeName(Ingredient.getOpcode()) << " "; printOperands(O, SlotTracker); } diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h --- a/llvm/lib/Transforms/Vectorize/VPlanValue.h +++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h @@ -36,6 +36,7 @@ class VPUser; class VPRecipeBase; class VPPredInstPHIRecipe; +class VPWidenMemoryInstructionRecipe; // This is the base class of the VPlan Def/Use graph, used for modeling the data // flow into, within and out of the VPlan. VPValues can stand for live-ins @@ -50,6 +51,7 @@ friend class VPSlotTracker; friend class VPRecipeBase; friend class VPPredInstPHIRecipe; + friend class VPWidenMemoryInstructionRecipe; const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).