-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[VPlan] Rename isUniform(AfterVectorization) to isSingleScalar (NFC). #140134
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 all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -1190,7 +1190,7 @@ void VPIRPhi::execute(VPTransformState &State) { | |||||
PHINode *Phi = &getIRPhi(); | ||||||
for (const auto &[Idx, Op] : enumerate(operands())) { | ||||||
VPValue *ExitValue = Op; | ||||||
auto Lane = vputils::isUniformAfterVectorization(ExitValue) | ||||||
auto Lane = vputils::isSingleScalar(ExitValue) | ||||||
? VPLane::getFirstLane() | ||||||
: VPLane::getLastLaneForVF(State.VF); | ||||||
VPBlockBase *Pred = getParent()->getPredecessors()[Idx]; | ||||||
|
@@ -2624,7 +2624,7 @@ static void scalarizeInstruction(const Instruction *Instr, | |||||
for (const auto &I : enumerate(RepRecipe->operands())) { | ||||||
auto InputLane = Lane; | ||||||
VPValue *Operand = I.value(); | ||||||
if (vputils::isUniformAfterVectorization(Operand)) | ||||||
if (vputils::isSingleScalar(Operand)) | ||||||
InputLane = VPLane::getFirstLane(); | ||||||
Cloned->setOperand(I.index(), State.get(Operand, InputLane)); | ||||||
} | ||||||
|
@@ -2650,7 +2650,7 @@ static void scalarizeInstruction(const Instruction *Instr, | |||||
void VPReplicateRecipe::execute(VPTransformState &State) { | ||||||
Instruction *UI = getUnderlyingInstr(); | ||||||
if (State.Lane) { // Generate a single instance. | ||||||
assert((State.VF.isScalar() || !isUniform()) && | ||||||
assert((State.VF.isScalar() || !isSingleScalar()) && | ||||||
"uniform recipe shouldn't be predicated"); | ||||||
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. Updated thanks |
||||||
assert(!State.VF.isScalable() && "Can't scalarize a scalable vector"); | ||||||
scalarizeInstruction(UI, this, *State.Lane, State); | ||||||
|
@@ -2668,16 +2668,15 @@ void VPReplicateRecipe::execute(VPTransformState &State) { | |||||
return; | ||||||
} | ||||||
|
||||||
if (IsUniform) { | ||||||
if (IsSingleScalar) { | ||||||
// Uniform within VL means we need to generate lane 0. | ||||||
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. Updated thanks |
||||||
scalarizeInstruction(UI, this, VPLane(0), State); | ||||||
return; | ||||||
} | ||||||
|
||||||
// A store of a loop varying value to a uniform address only needs the last | ||||||
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. updated thanks |
||||||
// copy of the store. | ||||||
if (isa<StoreInst>(UI) && | ||||||
vputils::isUniformAfterVectorization(getOperand(1))) { | ||||||
if (isa<StoreInst>(UI) && vputils::isSingleScalar(getOperand(1))) { | ||||||
auto Lane = VPLane::getLastLaneForVF(State.VF); | ||||||
scalarizeInstruction(UI, this, VPLane(Lane), State); | ||||||
return; | ||||||
|
@@ -2738,7 +2737,7 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF, | |||||
UI->getOpcode(), ResultTy, CostKind, | ||||||
{TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None}, | ||||||
Op2Info, Operands, UI, &Ctx.TLI) * | ||||||
(isUniform() ? 1 : VF.getKnownMinValue()); | ||||||
(isSingleScalar() ? 1 : VF.getKnownMinValue()); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -2748,7 +2747,7 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF, | |||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||||||
void VPReplicateRecipe::print(raw_ostream &O, const Twine &Indent, | ||||||
VPSlotTracker &SlotTracker) const { | ||||||
O << Indent << (IsUniform ? "CLONE " : "REPLICATE "); | ||||||
O << Indent << (IsSingleScalar ? "CLONE " : "REPLICATE "); | ||||||
|
||||||
if (!getUnderlyingInstr()->getType()->isVoidTy()) { | ||||||
printAsOperand(O, SlotTracker); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,7 @@ static bool sinkScalarOperands(VPlan &Plan) { | |
SinkCandidate->mayReadOrWriteMemory()) | ||
continue; | ||
if (auto *RepR = dyn_cast<VPReplicateRecipe>(SinkCandidate)) { | ||
if (!ScalarVFOnly && RepR->isUniform()) | ||
if (!ScalarVFOnly && RepR->isSingleScalar()) | ||
continue; | ||
} else if (!isa<VPScalarIVStepsRecipe>(SinkCandidate)) | ||
continue; | ||
|
@@ -347,7 +347,7 @@ static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe, | |
auto *RecipeWithoutMask = new VPReplicateRecipe( | ||
PredRecipe->getUnderlyingInstr(), | ||
make_range(PredRecipe->op_begin(), std::prev(PredRecipe->op_end())), | ||
PredRecipe->isUniform(), nullptr /*Mask*/, *PredRecipe); | ||
PredRecipe->isSingleScalar(), nullptr /*Mask*/, *PredRecipe); | ||
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. Independent: is PredRecipe->isSingleScalar() known to be false? |
||
auto *Pred = | ||
Plan.createVPBasicBlock(Twine(RegionName) + ".if", RecipeWithoutMask); | ||
|
||
|
@@ -643,12 +643,11 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) { | |
// Skip recipes that shouldn't be narrowed. | ||
if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) || | ||
Def->getNumUsers() == 0 || !Def->getUnderlyingValue() || | ||
(RepR && (RepR->isUniform() || RepR->isPredicated()))) | ||
(RepR && (RepR->isSingleScalar() || RepR->isPredicated()))) | ||
continue; | ||
|
||
// Skip recipes that may have other lanes than their first used. | ||
if (!vputils::isUniformAfterVectorization(Def) && | ||
!vputils::onlyFirstLaneUsed(Def)) | ||
if (!vputils::isSingleScalar(Def) && !vputils::onlyFirstLaneUsed(Def)) | ||
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. Independent: having only first lane used implied being single scalar, so suffice to check the former only, as explained? 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. Yes, those will need to be unified; 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.
|
||
continue; | ||
|
||
auto *Clone = new VPReplicateRecipe(Def->getUnderlyingInstr(), | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,7 +109,7 @@ bool vputils::isUniformAcrossVFsAndUFs(VPValue *V) { | |||||
// VPReplicateRecipe.IsUniform. They are also uniform across UF parts if | ||||||
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 |
||||||
// all their operands are invariant. | ||||||
// TODO: Further relax the restrictions. | ||||||
return R->isUniform() && | ||||||
return R->isSingleScalar() && | ||||||
(isa<LoadInst, StoreInst>(R->getUnderlyingValue())) && | ||||||
all_of(R->operands(), isUniformAcrossVFsAndUFs); | ||||||
}) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,8 +37,9 @@ VPValue *getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr, | |||||
/// SCEV expression could be constructed. | ||||||
const SCEV *getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE); | ||||||
|
||||||
/// Returns true if \p VPV is uniform after vectorization. | ||||||
inline bool isUniformAfterVectorization(const VPValue *VPV) { | ||||||
/// Returns true if \p VPV is a single scalar, either because it produces the | ||||||
/// same value for all lanes or only has its first lane used. | ||||||
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. Updated thanks |
||||||
inline bool isSingleScalar(const VPValue *VPV) { | ||||||
auto PreservesUniformity = [](unsigned Opcode) -> bool { | ||||||
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. BTW, does 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 as well, thanks |
||||||
if (Instruction::isBinaryOp(Opcode) || Instruction::isCast(Opcode)) | ||||||
return true; | ||||||
|
@@ -65,21 +66,19 @@ inline bool isUniformAfterVectorization(const VPValue *VPV) { | |||||
// lanes. | ||||||
if (RegionOfR && RegionOfR->isReplicator()) | ||||||
return false; | ||||||
return Rep->isUniform() || | ||||||
(PreservesUniformity(Rep->getOpcode()) && | ||||||
all_of(Rep->operands(), isUniformAfterVectorization)); | ||||||
return Rep->isSingleScalar() || (PreservesUniformity(Rep->getOpcode()) && | ||||||
all_of(Rep->operands(), isSingleScalar)); | ||||||
} | ||||||
if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe, VPBlendRecipe>(VPV)) | ||||||
return all_of(VPV->getDefiningRecipe()->operands(), | ||||||
isUniformAfterVectorization); | ||||||
return all_of(VPV->getDefiningRecipe()->operands(), isSingleScalar); | ||||||
if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) { | ||||||
return PreservesUniformity(WidenR->getOpcode()) && | ||||||
all_of(WidenR->operands(), isUniformAfterVectorization); | ||||||
all_of(WidenR->operands(), isSingleScalar); | ||||||
} | ||||||
if (auto *VPI = dyn_cast<VPInstruction>(VPV)) | ||||||
return VPI->isSingleScalar() || VPI->isVectorToScalar() || | ||||||
(PreservesUniformity(VPI->getOpcode()) && | ||||||
all_of(VPI->operands(), isUniformAfterVectorization)); | ||||||
all_of(VPI->operands(), isSingleScalar)); | ||||||
|
||||||
// VPExpandSCEVRecipes must be placed in the entry and are alway uniform. | ||||||
return isa<VPExpandSCEVRecipe>(VPV); | ||||||
|
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.
Independent: if VF.isScalar() implies isSingleScalar() (worth asserting elsewhere), suffice here to assert the latter.