Skip to content

Commit bbd3712

Browse files
committed
[VPlan] Use VPPhiAccessors for VPIRPhi.
1 parent 4939125 commit bbd3712

File tree

3 files changed

+54
-22
lines changed

3 files changed

+54
-22
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,8 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
17301730
/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
17311731
/// pointer induction. Produces either a vector PHI per-part or scalar values
17321732
/// per-lane based on the canonical induction.
1733-
class VPHeaderPHIRecipe : public VPSingleDefRecipe {
1733+
class VPHeaderPHIRecipe : public VPSingleDefRecipe,
1734+
public VPPhiAccessors<VPHeaderPHIRecipe> {
17341735
protected:
17351736
VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr,
17361737
VPValue *Start = nullptr, DebugLoc DL = {})
@@ -2616,7 +2617,8 @@ class VPBranchOnMaskRecipe : public VPRecipeBase {
26162617
/// order to merge values that are set under such a branch and feed their uses.
26172618
/// The phi nodes can be scalar or vector depending on the users of the value.
26182619
/// This recipe works in concert with VPBranchOnMaskRecipe.
2619-
class VPPredInstPHIRecipe : public VPSingleDefRecipe {
2620+
class VPPredInstPHIRecipe : public VPSingleDefRecipe,
2621+
public VPPhiAccessors<VPPredInstPHIRecipe> {
26202622
public:
26212623
/// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
26222624
/// nodes after merging back from a Branch-on-Mask.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,12 @@ void VPWidenCastRecipe::print(raw_ostream &O, const Twine &Indent,
17451745
}
17461746
#endif
17471747

1748+
template <>
1749+
const VPBasicBlock *
1750+
VPPhiAccessors<VPHeaderPHIRecipe>::getIncomingBlock(unsigned Idx) const {
1751+
return getIncomingBlockForRecipe(getAsRecipe(), Idx);
1752+
}
1753+
17481754
InstructionCost VPHeaderPHIRecipe::computeCost(ElementCount VF,
17491755
VPCostContext &Ctx) const {
17501756
return Ctx.TTI.getCFInstrCost(Instruction::PHI, Ctx.CostKind);
@@ -2537,6 +2543,14 @@ InstructionCost VPBranchOnMaskRecipe::computeCost(ElementCount VF,
25372543
// now.
25382544
return 0;
25392545
}
2546+
template <>
2547+
const VPBasicBlock *
2548+
VPPhiAccessors<VPPredInstPHIRecipe>::getIncomingBlock(unsigned Idx) const {
2549+
assert(Idx == 0 && "Only one incoming block available");
2550+
// VPPredInstPHIRecipe only has a single incoming value, which corresponds to
2551+
// the second predecessor.
2552+
return getIncomingBlockForRecipe(getAsRecipe(), 1);
2553+
}
25402554

25412555
void VPPredInstPHIRecipe::execute(VPTransformState &State) {
25422556
State.setDebugLocFrom(getDebugLoc());

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
175175
if (!verifyPhiRecipes(VPBB))
176176
return false;
177177

178-
// Verify that defs in VPBB dominate all their uses. The current
179-
// implementation is still incomplete.
178+
// Verify that defs in VPBB dominate all their uses.
180179
DenseMap<const VPRecipeBase *, unsigned> RecipeNumbering;
181180
unsigned Cnt = 0;
182181
for (const VPRecipeBase &R : *VPBB)
@@ -203,25 +202,42 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
203202

204203
for (const VPUser *U : V->users()) {
205204
auto *UI = cast<VPRecipeBase>(U);
206-
// TODO: check dominance of incoming values for phis properly.
207-
if (!UI || isa<VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPredInstPHIRecipe,
208-
VPIRPhi>(UI))
209-
continue;
210-
211-
// If the user is in the same block, check it comes after R in the
212-
// block.
213-
if (UI->getParent() == VPBB) {
214-
if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
215-
errs() << "Use before def!\n";
216-
return false;
217-
}
218-
continue;
219-
}
220-
221-
if (!VPDT.dominates(VPBB, UI->getParent())) {
222-
errs() << "Use before def!\n";
205+
const VPBlockBase *UserVPBB = UI->getParent();
206+
bool Ok =
207+
TypeSwitch<VPRecipeBase *, bool>(
208+
const_cast<VPRecipeBase *>(cast<VPRecipeBase>(U)))
209+
.Case<VPWidenPHIRecipe, VPHeaderPHIRecipe, VPPredInstPHIRecipe,
210+
VPIRPhi>([&](auto *R) {
211+
for (const auto &[IncVPV, IncVPBB] :
212+
R->incoming_values_and_blocks()) {
213+
if (IncVPV != V)
214+
continue;
215+
if (IncVPBB != VPBB && !VPDT.dominates(VPBB, IncVPBB)) {
216+
errs() << "Use before def!\n";
217+
return false;
218+
}
219+
}
220+
return true;
221+
})
222+
.Default([&](const VPUser *U) {
223+
// If the user is in the same block, check it comes after R in
224+
// the block.
225+
if (UserVPBB == VPBB) {
226+
if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
227+
errs() << "Use before def!\n";
228+
return false;
229+
}
230+
return true;
231+
}
232+
233+
if (!VPDT.dominates(VPBB, UserVPBB)) {
234+
errs() << "Use before def!\n";
235+
return false;
236+
}
237+
return true;
238+
});
239+
if (!Ok)
223240
return false;
224-
}
225241
}
226242
}
227243
if (const auto *EVL = dyn_cast<VPInstruction>(&R)) {

0 commit comments

Comments
 (0)