Skip to content

Commit 0834362

Browse files
committed
Cache placeholder values
1 parent d2fe632 commit 0834362

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,8 +3045,11 @@ class VPExpressionRecipe : public VPSingleDefRecipe {
30453045
if (ExpressionRecipesSeen.insert(R).second)
30463046
delete R;
30473047
}
3048-
for (VPValue *T : LiveInPlaceholders)
3049-
delete T;
3048+
SmallSet<VPValue *, 4> PlaceholdersSeen;
3049+
for (VPValue *T : LiveInPlaceholders) {
3050+
if (PlaceholdersSeen.insert(T).second)
3051+
delete T;
3052+
}
30503053
}
30513054

30523055
VP_CLASSOF_IMPL(VPDef::VPExpressionSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,34 +2790,32 @@ VPExpressionRecipe::VPExpressionRecipe(
27902790
R->removeFromParent();
27912791
}
27922792

2793-
// Keep track of how many instances of each recipe occur in the recipe list
2794-
SmallMapVector<VPSingleDefRecipe *, unsigned, 4> ExpressionRecipeCounts;
2795-
for (auto *R : ExpressionRecipes) {
2796-
auto *F = ExpressionRecipeCounts.find(R);
2797-
if (F == ExpressionRecipeCounts.end())
2798-
ExpressionRecipeCounts.insert(std::make_pair(R, 1));
2799-
else
2800-
F->second++;
2801-
}
2802-
28032793
// Internalize all external operands to the expression recipes. To do so,
28042794
// create new temporary VPValues for all operands defined by a recipe outside
28052795
// the expression. The original operands are added as operands of the
28062796
// VPExpressionRecipe itself.
2797+
2798+
// This map caches the temporary placeholders so duplicates aren't created in
2799+
// the case that recipes share operands.
2800+
SmallMapVector<VPValue *, VPValue *, 4> OperandPlaceholders;
2801+
28072802
for (auto *R : ExpressionRecipes) {
2808-
auto *F = ExpressionRecipeCounts.find(R);
2809-
F->second--;
28102803
for (const auto &[Idx, Op] : enumerate(R->operands())) {
28112804
auto *Def = Op->getDefiningRecipe();
28122805
if (Def && ExpressionRecipesAsSetOfUsers.contains(Def))
28132806
continue;
28142807
addOperand(Op);
2815-
auto *Tmp = new VPValue();
2816-
LiveInPlaceholders.push_back(Tmp);
2817-
// Only modify this recipe's operands if it's the last time it occurs in
2818-
// the recipe list
2819-
if (F->second == 0)
2820-
R->setOperand(Idx, Tmp);
2808+
if (OperandPlaceholders.find(Op) == OperandPlaceholders.end())
2809+
OperandPlaceholders[Op] = new VPValue();
2810+
LiveInPlaceholders.push_back(OperandPlaceholders[Op]);
2811+
}
2812+
}
2813+
2814+
for (auto *R : ExpressionRecipes) {
2815+
for (const auto &[Idx, Op] : enumerate(R->operands())) {
2816+
auto *Entry = OperandPlaceholders.find(Op);
2817+
if (Entry != OperandPlaceholders.end())
2818+
R->setOperand(Idx, Entry->second);
28212819
}
28222820
}
28232821
}

0 commit comments

Comments
 (0)