Skip to content

[LV] Strip unnecessary make_{pair,optional} (NFC) #141924

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

Merged
merged 2 commits into from
Jun 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ class LoopVectorizationCostModel {
void setWideningDecision(Instruction *I, ElementCount VF, InstWidening W,
InstructionCost Cost) {
assert(VF.isVector() && "Expected VF >=2");
WideningDecisions[std::make_pair(I, VF)] = std::make_pair(W, Cost);
WideningDecisions[{I, VF}] = {W, Cost};
}

/// Save vectorization decision \p W and \p Cost taken by the cost model for
Expand All @@ -1102,11 +1102,9 @@ class LoopVectorizationCostModel {
for (unsigned Idx = 0; Idx < Grp->getFactor(); ++Idx) {
if (auto *I = Grp->getMember(Idx)) {
if (Grp->getInsertPos() == I)
WideningDecisions[std::make_pair(I, VF)] =
std::make_pair(W, InsertPosCost);
WideningDecisions[{I, VF}] = {W, InsertPosCost};
else
WideningDecisions[std::make_pair(I, VF)] =
std::make_pair(W, OtherMemberCost);
WideningDecisions[{I, VF}] = {W, OtherMemberCost};
}
}
}
Expand All @@ -1120,7 +1118,7 @@ class LoopVectorizationCostModel {
TheLoop->isInnermost() &&
"cost-model should not be used for outer loops (in VPlan-native path)");

std::pair<Instruction *, ElementCount> InstOnVF = std::make_pair(I, VF);
std::pair<Instruction *, ElementCount> InstOnVF(I, VF);
auto Itr = WideningDecisions.find(InstOnVF);
if (Itr == WideningDecisions.end())
return CM_Unknown;
Expand All @@ -1131,7 +1129,7 @@ class LoopVectorizationCostModel {
/// width \p VF.
InstructionCost getWideningCost(Instruction *I, ElementCount VF) {
assert(VF.isVector() && "Expected VF >=2");
std::pair<Instruction *, ElementCount> InstOnVF = std::make_pair(I, VF);
std::pair<Instruction *, ElementCount> InstOnVF(I, VF);
assert(WideningDecisions.contains(InstOnVF) &&
"The cost is not calculated");
return WideningDecisions[InstOnVF].second;
Expand All @@ -1150,8 +1148,7 @@ class LoopVectorizationCostModel {
std::optional<unsigned> MaskPos,
InstructionCost Cost) {
assert(!VF.isScalar() && "Expected vector VF");
CallWideningDecisions[std::make_pair(CI, VF)] = {Kind, Variant, IID,
MaskPos, Cost};
CallWideningDecisions[{CI, VF}] = {Kind, Variant, IID, MaskPos, Cost};
}

CallWideningDecision getCallWideningDecision(CallInst *CI,
Expand Down Expand Up @@ -1348,21 +1345,20 @@ class LoopVectorizationCostModel {
void setTailFoldingStyles(bool IsScalableVF, unsigned UserIC) {
assert(!ChosenTailFoldingStyle && "Tail folding must not be selected yet.");
if (!Legal->canFoldTailByMasking()) {
ChosenTailFoldingStyle =
std::make_pair(TailFoldingStyle::None, TailFoldingStyle::None);
ChosenTailFoldingStyle = {TailFoldingStyle::None, TailFoldingStyle::None};
return;
}

if (!ForceTailFoldingStyle.getNumOccurrences()) {
ChosenTailFoldingStyle = std::make_pair(
ChosenTailFoldingStyle = {
TTI.getPreferredTailFoldingStyle(/*IVUpdateMayOverflow=*/true),
TTI.getPreferredTailFoldingStyle(/*IVUpdateMayOverflow=*/false));
TTI.getPreferredTailFoldingStyle(/*IVUpdateMayOverflow=*/false)};
return;
}

// Set styles when forced.
ChosenTailFoldingStyle = std::make_pair(ForceTailFoldingStyle.getValue(),
ForceTailFoldingStyle.getValue());
ChosenTailFoldingStyle = {ForceTailFoldingStyle.getValue(),
ForceTailFoldingStyle.getValue()};
if (ForceTailFoldingStyle != TailFoldingStyle::DataWithEVL)
return;
// Override forced styles if needed.
Expand All @@ -1375,9 +1371,8 @@ class LoopVectorizationCostModel {
// If for some reason EVL mode is unsupported, fallback to
// DataWithoutLaneMask to try to vectorize the loop with folded tail
// in a generic way.
ChosenTailFoldingStyle =
std::make_pair(TailFoldingStyle::DataWithoutLaneMask,
TailFoldingStyle::DataWithoutLaneMask);
ChosenTailFoldingStyle = {TailFoldingStyle::DataWithoutLaneMask,
TailFoldingStyle::DataWithoutLaneMask};
LLVM_DEBUG(
dbgs()
<< "LV: Preference for VP intrinsics indicated. Will "
Expand Down Expand Up @@ -8135,7 +8130,7 @@ void VPRecipeBuilder::collectScaledReductions(VFRange &Range) {
PartialReductionChain Chain = Pair.first;
if (ExtendIsOnlyUsedByPartialReductions(Chain.ExtendA) &&
ExtendIsOnlyUsedByPartialReductions(Chain.ExtendB))
ScaledReductionMap.insert(std::make_pair(Chain.Reduction, Pair.second));
ScaledReductionMap.try_emplace(Chain.Reduction, Pair.second);
}
}

Expand Down Expand Up @@ -8207,12 +8202,11 @@ bool VPRecipeBuilder::getScaledReductions(
[&](ElementCount VF) {
InstructionCost Cost = TTI->getPartialReductionCost(
Update->getOpcode(), A->getType(), B->getType(), PHI->getType(),
VF, OpAExtend, OpBExtend,
std::make_optional(BinOp->getOpcode()));
VF, OpAExtend, OpBExtend, BinOp->getOpcode());
return Cost.isValid();
},
Range)) {
Chains.push_back(std::make_pair(Chain, TargetScaleFactor));
Chains.emplace_back(Chain, TargetScaleFactor);
return true;
}

Expand Down Expand Up @@ -10105,9 +10099,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
bool VectorizeLoop = true, InterleaveLoop = true;
if (VF.Width.isScalar()) {
LLVM_DEBUG(dbgs() << "LV: Vectorization is possible but not beneficial.\n");
VecDiagMsg = std::make_pair(
VecDiagMsg = {
"VectorizationNotBeneficial",
"the cost-model indicates that vectorization is not beneficial");
"the cost-model indicates that vectorization is not beneficial"};
VectorizeLoop = false;
}

Expand All @@ -10116,16 +10110,15 @@ bool LoopVectorizePass::processLoop(Loop *L) {
// requested.
LLVM_DEBUG(dbgs() << "LV: Ignoring UserIC, because vectorization and "
"interleaving should be avoided up front\n");
IntDiagMsg = std::make_pair(
"InterleavingAvoided",
"Ignoring UserIC, because interleaving was avoided up front");
IntDiagMsg = {"InterleavingAvoided",
"Ignoring UserIC, because interleaving was avoided up front"};
InterleaveLoop = false;
} else if (IC == 1 && UserIC <= 1) {
// Tell the user interleaving is not beneficial.
LLVM_DEBUG(dbgs() << "LV: Interleaving is not beneficial.\n");
IntDiagMsg = std::make_pair(
IntDiagMsg = {
"InterleavingNotBeneficial",
"the cost-model indicates that interleaving is not beneficial");
"the cost-model indicates that interleaving is not beneficial"};
InterleaveLoop = false;
if (UserIC == 1) {
IntDiagMsg.first = "InterleavingNotBeneficialAndDisabled";
Expand All @@ -10136,10 +10129,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
// Tell the user interleaving is beneficial, but it explicitly disabled.
LLVM_DEBUG(
dbgs() << "LV: Interleaving is beneficial but is explicitly disabled.");
IntDiagMsg = std::make_pair(
"InterleavingBeneficialButDisabled",
"the cost-model indicates that interleaving is beneficial "
"but is explicitly disabled or interleave count is set to 1");
IntDiagMsg = {"InterleavingBeneficialButDisabled",
"the cost-model indicates that interleaving is beneficial "
"but is explicitly disabled or interleave count is set to 1"};
InterleaveLoop = false;
}

Expand All @@ -10149,10 +10141,10 @@ bool LoopVectorizePass::processLoop(Loop *L) {
if (!VectorizeLoop && InterleaveLoop && LVL.hasHistograms()) {
LLVM_DEBUG(dbgs() << "LV: Not interleaving without vectorization due "
<< "to histogram operations.\n");
IntDiagMsg = std::make_pair(
IntDiagMsg = {
"HistogramPreventsScalarInterleaving",
"Unable to interleave without vectorization due to constraints on "
"the order of histogram operations");
"the order of histogram operations"};
InterleaveLoop = false;
}

Expand Down
Loading