-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[VPlan] Use VPInstruction for VPScalarPHIRecipe. (NFCI) #129767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b05ac80
4a8d4da
af491b4
0d9e1fb
0b65489
963bc78
b279a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -1074,9 +1074,15 @@ void VPlan::execute(VPTransformState *State) { | |||||||
Inc->setOperand(0, State->get(IV->getLastUnrolledPartOperand())); | ||||||||
continue; | ||||||||
} | ||||||||
if (auto *VPI = dyn_cast<VPInstruction>(&R)) { | ||||||||
Value *Phi = State->get(VPI, true); | ||||||||
Value *Val = State->get(VPI->getOperand(1), true); | ||||||||
cast<PHINode>(Phi)->addIncoming(Val, VectorLatchBB); | ||||||||
continue; | ||||||||
} | ||||||||
|
||||||||
auto *PhiR = cast<VPHeaderPHIRecipe>(&R); | ||||||||
bool NeedsScalar = isa<VPScalarPHIRecipe>(PhiR) || | ||||||||
bool NeedsScalar = | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(w/o it can drop enclosing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks |
||||||||
(isa<VPReductionPHIRecipe>(PhiR) && | ||||||||
cast<VPReductionPHIRecipe>(PhiR)->isInLoop()); | ||||||||
Value *Phi = State->get(PhiR, NeedsScalar); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks |
||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -71,6 +71,10 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) { | |||||||||
} | ||||||||||
case VPInstruction::ExplicitVectorLength: | ||||||||||
return Type::getIntNTy(Ctx, 32); | ||||||||||
case Instruction::PHI: | ||||||||||
// Avoid inferring the type for other operands, as this may lead to infinite | ||||||||||
// recursions for cycles. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks! |
||||||||||
return inferScalarType(R->getOperand(0)); | ||||||||||
case VPInstruction::FirstOrderRecurrenceSplice: | ||||||||||
case VPInstruction::Not: | ||||||||||
case VPInstruction::ResumePhi: | ||||||||||
|
@@ -236,14 +240,14 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) { | |||||||||
TypeSwitch<const VPRecipeBase *, Type *>(V->getDefiningRecipe()) | ||||||||||
.Case<VPActiveLaneMaskPHIRecipe, VPCanonicalIVPHIRecipe, | ||||||||||
VPFirstOrderRecurrencePHIRecipe, VPReductionPHIRecipe, | ||||||||||
VPWidenPointerInductionRecipe, VPEVLBasedIVPHIRecipe, | ||||||||||
VPScalarPHIRecipe>([this](const auto *R) { | ||||||||||
// Handle header phi recipes, except VPWidenIntOrFpInduction | ||||||||||
// which needs special handling due it being possibly truncated. | ||||||||||
// TODO: consider inferring/caching type of siblings, e.g., | ||||||||||
// backedge value, here and in cases below. | ||||||||||
return inferScalarType(R->getStartValue()); | ||||||||||
}) | ||||||||||
VPWidenPointerInductionRecipe, VPEVLBasedIVPHIRecipe>( | ||||||||||
[this](const auto *R) { | ||||||||||
// Handle header phi recipes, except VPWidenIntOrFpInduction | ||||||||||
// which needs special handling due it being possibly truncated. | ||||||||||
// TODO: consider inferring/caching type of siblings, e.g., | ||||||||||
// backedge value, here and in cases below. | ||||||||||
return inferScalarType(R->getStartValue()); | ||||||||||
}) | ||||||||||
.Case<VPWidenIntOrFpInductionRecipe, VPDerivedIVRecipe>( | ||||||||||
[](const auto *R) { return R->getScalarType(); }) | ||||||||||
.Case<VPReductionRecipe, VPPredInstPHIRecipe, VPWidenPHIRecipe, | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -277,6 +277,11 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF, | |||||||||
VPCostContext &Ctx) const { | ||||||||||
llvm_unreachable("subclasses should implement computeCost"); | ||||||||||
} | ||||||||||
bool VPRecipeBase::isPhi() const { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, is this missing a newline above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, thanks |
||||||||||
return (getVPDefID() >= VPFirstPHISC && getVPDefID() <= VPLastPHISC) || | ||||||||||
(isa<VPInstruction>(this) && | ||||||||||
cast<VPInstruction>(this)->getOpcode() == Instruction::PHI); | ||||||||||
} | ||||||||||
|
||||||||||
InstructionCost | ||||||||||
VPPartialReductionRecipe::computeCost(ElementCount VF, | ||||||||||
|
@@ -418,6 +423,7 @@ bool VPInstruction::canGenerateScalarForFirstLane() const { | |||||||||
if (isSingleScalar() || isVectorToScalar()) | ||||||||||
return true; | ||||||||||
switch (Opcode) { | ||||||||||
case Instruction::PHI: | ||||||||||
case Instruction::ICmp: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
lex order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks! |
||||||||||
case Instruction::Select: | ||||||||||
case VPInstruction::BranchOnCond: | ||||||||||
|
@@ -458,6 +464,13 @@ Value *VPInstruction::generate(VPTransformState &State) { | |||||||||
} | ||||||||||
|
||||||||||
switch (getOpcode()) { | ||||||||||
case Instruction::PHI: { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhere it should be documented that VPInstructions of PHI opcode are used to model header phi's only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment here, thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Perhaps worth an assert? VPInstructions with phi opcodes could be used for non-header phi's prior to predication. Eventually also for uniform branches, and out-of-loop branches. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added assert, thanks! Will generalize this using #129389 once it lands |
||||||||||
BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this); | ||||||||||
Value *Start = State.get(getOperand(0), VPLane(0)); | ||||||||||
PHINode *Phi = State.Builder.CreatePHI(Start->getType(), 2, Name); | ||||||||||
Phi->addIncoming(Start, VectorPH); | ||||||||||
return Phi; | ||||||||||
} | ||||||||||
case VPInstruction::Not: { | ||||||||||
Value *A = State.get(getOperand(0)); | ||||||||||
return Builder.CreateNot(A, Name); | ||||||||||
|
@@ -838,6 +851,8 @@ bool VPInstruction::onlyFirstLaneUsed(const VPValue *Op) const { | |||||||||
switch (getOpcode()) { | ||||||||||
default: | ||||||||||
return false; | ||||||||||
case Instruction::PHI: | ||||||||||
return true; | ||||||||||
case Instruction::ICmp: | ||||||||||
case Instruction::Select: | ||||||||||
case Instruction::Or: | ||||||||||
|
@@ -3283,11 +3298,12 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) { | |||||||||
BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this); | ||||||||||
PHINode *NewPointerPhi = nullptr; | ||||||||||
if (CurrentPart == 0) { | ||||||||||
auto *IVR = cast<VPHeaderPHIRecipe>(&getParent() | ||||||||||
->getPlan() | ||||||||||
->getVectorLoopRegion() | ||||||||||
->getEntryBasicBlock() | ||||||||||
->front()); | ||||||||||
auto *IVR = getParent() | ||||||||||
->getPlan() | ||||||||||
->getVectorLoopRegion() | ||||||||||
->getEntryBasicBlock() | ||||||||||
->front() | ||||||||||
.getVPSingleValue(); | ||||||||||
Comment on lines
+3316
to
+3321
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independently: is there a better way to retrieve IVR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be part of the operands. Will look into this separately. |
||||||||||
PHINode *CanonicalIV = cast<PHINode>(State.get(IVR, /*IsScalar*/ true)); | ||||||||||
NewPointerPhi = PHINode::Create(ScStValueType, 2, "pointer.phi", | ||||||||||
CanonicalIV->getIterator()); | ||||||||||
|
@@ -3666,22 +3682,3 @@ void VPEVLBasedIVPHIRecipe::print(raw_ostream &O, const Twine &Indent, | |||||||||
printOperands(O, SlotTracker); | ||||||||||
} | ||||||||||
#endif | ||||||||||
|
||||||||||
void VPScalarPHIRecipe::execute(VPTransformState &State) { | ||||||||||
BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this); | ||||||||||
Value *Start = State.get(getStartValue(), VPLane(0)); | ||||||||||
PHINode *Phi = State.Builder.CreatePHI(Start->getType(), 2, Name); | ||||||||||
Phi->addIncoming(Start, VectorPH); | ||||||||||
Phi->setDebugLoc(getDebugLoc()); | ||||||||||
State.set(this, Phi, /*IsScalar=*/true); | ||||||||||
} | ||||||||||
|
||||||||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||||||||||
void VPScalarPHIRecipe::print(raw_ostream &O, const Twine &Indent, | ||||||||||
VPSlotTracker &SlotTracker) const { | ||||||||||
O << Indent << "SCALAR-PHI "; | ||||||||||
printAsOperand(O, SlotTracker); | ||||||||||
O << " = phi "; | ||||||||||
printOperands(O, SlotTracker); | ||||||||||
} | ||||||||||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,12 +143,13 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const { | |
}) | ||
.Case<VPWidenStoreEVLRecipe, VPReductionEVLRecipe>( | ||
[&](const VPRecipeBase *S) { return VerifyEVLUse(*S, 2); }) | ||
.Case<VPWidenLoadEVLRecipe, VPReverseVectorPointerRecipe, | ||
VPScalarPHIRecipe>( | ||
.Case<VPWidenLoadEVLRecipe, VPReverseVectorPointerRecipe>( | ||
[&](const VPRecipeBase *R) { return VerifyEVLUse(*R, 1); }) | ||
.Case<VPScalarCastRecipe>( | ||
[&](const VPScalarCastRecipe *S) { return VerifyEVLUse(*S, 0); }) | ||
.Case<VPInstruction>([&](const VPInstruction *I) { | ||
if (I->getOpcode() == Instruction::PHI) | ||
return VerifyEVLUse(*I, I->getNumOperands() - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to use 1, thanks! |
||
if (I->getOpcode() != Instruction::Add) { | ||
errs() << "EVL is used as an operand in non-VPInstruction::Add\n"; | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suffice to
so State->get() works for both VPHeaderPHIRecipes and VPInstructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!