Skip to content

Commit

Permalink
[VPlan] Make VPWidenMemoryInstructionRecipe a VPDef.
Browse files Browse the repository at this point in the history
This patch updates VPWidenMemoryInstructionRecipe to use VPDef
to manage the value it produces instead of inheriting from VPValue.

Reviewed By: gilr

Differential Revision: https://reviews.llvm.org/D90563
  • Loading branch information
fhahn committed Dec 14, 2020
1 parent aabaca3 commit e42e526
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
9 changes: 4 additions & 5 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Expand Up @@ -8827,11 +8827,10 @@ void VPPredInstPHIRecipe::execute(VPTransformState &State) {
}

void VPWidenMemoryInstructionRecipe::execute(VPTransformState &State) {
Instruction *Instr = getUnderlyingInstr();
VPValue *StoredValue = isa<StoreInst>(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
Expand Down
20 changes: 14 additions & 6 deletions llvm/lib/Transforms/Vectorize/VPlan.cpp
Expand Up @@ -124,8 +124,12 @@ VPValue *VPRecipeBase::toVPValue() {
return V;
if (auto *V = dyn_cast<VPReductionRecipe>(this))
return V;
if (auto *V = dyn_cast<VPWidenMemoryInstructionRecipe>(this))
return V;
if (auto *V = dyn_cast<VPWidenMemoryInstructionRecipe>(this)) {
if (!V->isStore())
return V->getVPValue();
else
return nullptr;
}
if (auto *V = dyn_cast<VPWidenCallRecipe>(this))
return V;
if (auto *V = dyn_cast<VPWidenSelectRecipe>(this))
Expand All @@ -144,8 +148,12 @@ const VPValue *VPRecipeBase::toVPValue() const {
return V;
if (auto *V = dyn_cast<VPReductionRecipe>(this))
return V;
if (auto *V = dyn_cast<VPWidenMemoryInstructionRecipe>(this))
return V;
if (auto *V = dyn_cast<VPWidenMemoryInstructionRecipe>(this)) {
if (!V->isStore())
return V->getVPValue();
else
return nullptr;
}
if (auto *V = dyn_cast<VPWidenCallRecipe>(this))
return V;
if (auto *V = dyn_cast<VPWidenSelectRecipe>(this))
Expand Down Expand Up @@ -993,10 +1001,10 @@ void VPWidenMemoryInstructionRecipe::print(raw_ostream &O, const Twine &Indent,
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);
}
Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Expand Up @@ -1265,8 +1265,9 @@ class VPPredInstPHIRecipe : public VPRecipeBase, public VPUser {
/// 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)
Expand All @@ -1280,16 +1281,16 @@ class VPWidenMemoryInstructionRecipe : public VPRecipeBase,

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);
}

Expand All @@ -1311,7 +1312,7 @@ class VPWidenMemoryInstructionRecipe : public VPRecipeBase,
}

/// Returns true if this recipe is a store.
bool isStore() const { return isa<StoreInst>(getUnderlyingInstr()); }
bool isStore() const { return isa<StoreInst>(Ingredient); }

/// Return the address accessed by this recipe.
VPValue *getStoredValue() const {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlanValue.h
Expand Up @@ -36,6 +36,7 @@ class VPSlotTracker;
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
Expand All @@ -50,6 +51,7 @@ class VPValue {
friend class VPSlotTracker;
friend class VPRecipeBase;
friend class VPPredInstPHIRecipe;
friend class VPWidenMemoryInstructionRecipe;

const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).

Expand Down

0 comments on commit e42e526

Please sign in to comment.