-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[VPlan] Introduce vputils::getSingleScalarClone #161667
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
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -189,19 +189,7 @@ static bool sinkScalarOperands(VPlan &Plan) { | |
if (NeedsDuplicating) { | ||
if (ScalarVFOnly) | ||
continue; | ||
VPSingleDefRecipe *Clone; | ||
if (auto *SinkCandidateRepR = | ||
dyn_cast<VPReplicateRecipe>(SinkCandidate)) { | ||
// TODO: Handle converting to uniform recipes as separate transform, | ||
// then cloning should be sufficient here. | ||
Instruction *I = SinkCandidate->getUnderlyingInstr(); | ||
Clone = new VPReplicateRecipe(I, SinkCandidate->operands(), true, | ||
nullptr /*Mask*/, *SinkCandidateRepR); | ||
// TODO: add ".cloned" suffix to name of Clone's VPValue. | ||
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. Worth adding the TODO to getSingleScalarClone? 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. Worth noting that the constructor doesn't accept a Name field, so I'm not sure if we're going to resolve this: kept it for now. |
||
} else { | ||
Clone = SinkCandidate->clone(); | ||
} | ||
|
||
VPSingleDefRecipe *Clone = vputils::getSingleScalarClone(SinkCandidate); | ||
Clone->insertBefore(SinkCandidate); | ||
SinkCandidate->replaceUsesWithIf(Clone, [SinkTo](VPUser &U, unsigned) { | ||
return cast<VPRecipeBase>(&U)->getParent() != SinkTo; | ||
|
@@ -667,8 +655,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) { | |
if (!vputils::isSingleScalar(Def) && !vputils::onlyFirstLaneUsed(Def)) | ||
continue; | ||
|
||
auto *Clone = new VPReplicateRecipe(Def->getUnderlyingInstr(), | ||
Def->operands(), /*IsUniform*/ true); | ||
VPSingleDefRecipe *Clone = vputils::getSingleScalarClone(Def); | ||
Clone->insertAfter(Def); | ||
Def->replaceAllUsesWith(Clone); | ||
} | ||
|
@@ -1335,9 +1322,8 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) { | |
auto *RepOrWidenR = cast<VPSingleDefRecipe>(&R); | ||
if (RepR && isa<StoreInst>(RepR->getUnderlyingInstr()) && | ||
vputils::isSingleScalar(RepR->getOperand(1))) { | ||
auto *Clone = new VPReplicateRecipe( | ||
RepOrWidenR->getUnderlyingInstr(), RepOrWidenR->operands(), | ||
true /*IsSingleScalar*/, nullptr /*Mask*/, *RepR /*Metadata*/); | ||
auto *Clone = | ||
cast<VPReplicateRecipe>(vputils::getSingleScalarClone(RepOrWidenR)); | ||
Clone->insertBefore(RepOrWidenR); | ||
unsigned ExtractOpc = | ||
vputils::isUniformAcrossVFsAndUFs(RepR->getOperand(1)) | ||
|
@@ -1362,9 +1348,7 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) { | |
})) | ||
continue; | ||
|
||
auto *Clone = new VPReplicateRecipe(RepOrWidenR->getUnderlyingInstr(), | ||
RepOrWidenR->operands(), | ||
true /*IsSingleScalar*/); | ||
VPSingleDefRecipe *Clone = vputils::getSingleScalarClone(RepOrWidenR); | ||
Clone->insertBefore(RepOrWidenR); | ||
RepOrWidenR->replaceAllUsesWith(Clone); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -253,3 +253,25 @@ vputils::getRecipesForUncountableExit(VPlan &Plan, | |
|
||
return UncountableCondition; | ||
} | ||
|
||
VPSingleDefRecipe *vputils::getSingleScalarClone(VPSingleDefRecipe *R) { | ||
// TODO: add ".cloned" suffix to name of Clone's VPValue. | ||
return TypeSwitch<VPSingleDefRecipe *, VPSingleDefRecipe *>(R) | ||
.Case<VPInstruction, VPWidenRecipe, VPWidenSelectRecipe, | ||
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. What about all the other VPSingleDefRecipe types, i.e. VPWidenPHIRecipe, VPBlendRecipe, VPExpressionRecipe, VPWidenCanonicalIVRecipe, etc? I'm a bit nervous that we might be missing some cases here. Have you tried running the LLVM test suite to catch any missing cases? 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. Should be fine for the moment, as all the uses in the use-sites are covered: when we add more recipes to handle in the use-sites, we should update this (follow-ups planned). |
||
VPWidenCallRecipe, VPReplicateRecipe>([](auto *I) { | ||
return new VPReplicateRecipe(I->getUnderlyingInstr(), I->operands(), | ||
/*IsSingleScalar*/ true, | ||
/*Mask*/ nullptr, | ||
/*Metadata*/ *I); | ||
}) | ||
.Case<VPWidenGEPRecipe>([](auto *I) { | ||
// WidenGEP does not have metadata. | ||
return new VPReplicateRecipe(I->getUnderlyingInstr(), I->operands(), | ||
/*IsSingleScalar*/ true, /*Mask*/ nullptr); | ||
}) | ||
.Case<VPScalarIVStepsRecipe>([](auto *I) { return I->clone(); }) | ||
.Default([](auto *I) { | ||
llvm_unreachable("Don't know how to convert to single-scalar"); | ||
return nullptr; | ||
}); | ||
} |
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.
Do we want to keep the TODO?
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.
Perhaps not? I think we wanted to address it sometime in the past, but I don't think it's the case any longer?