Skip to content

Commit 73559dd

Browse files
committed
Address review
1 parent 0834362 commit 73559dd

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,7 +2978,8 @@ class LLVM_ABI_FOR_TEST VPBranchOnMaskRecipe : public VPRecipeBase {
29782978
/// the expression is elevated to connect the non-expression recipe with the
29792979
/// VPExpressionRecipe itself.
29802980
class VPExpressionRecipe : public VPSingleDefRecipe {
2981-
/// Recipes included in this VPExpressionRecipe.
2981+
/// Recipes included in this VPExpressionRecipe. This could contain
2982+
/// duplicates.
29822983
SmallVector<VPSingleDefRecipe *> ExpressionRecipes;
29832984

29842985
/// Temporary VPValues used for external operands of the expression, i.e.
@@ -3045,11 +3046,8 @@ class VPExpressionRecipe : public VPSingleDefRecipe {
30453046
if (ExpressionRecipesSeen.insert(R).second)
30463047
delete R;
30473048
}
3048-
SmallSet<VPValue *, 4> PlaceholdersSeen;
3049-
for (VPValue *T : LiveInPlaceholders) {
3050-
if (PlaceholdersSeen.insert(T).second)
3051-
delete T;
3052-
}
3049+
for (VPValue *T : LiveInPlaceholders)
3050+
delete T;
30533051
}
30543052

30553053
VP_CLASSOF_IMPL(VPDef::VPExpressionSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,33 +2795,28 @@ VPExpressionRecipe::VPExpressionRecipe(
27952795
// the expression. The original operands are added as operands of the
27962796
// VPExpressionRecipe itself.
27972797

2798-
// This map caches the temporary placeholders so duplicates aren't created in
2799-
// the case that recipes share operands.
28002798
SmallMapVector<VPValue *, VPValue *, 4> OperandPlaceholders;
2801-
28022799
for (auto *R : ExpressionRecipes) {
28032800
for (const auto &[Idx, Op] : enumerate(R->operands())) {
28042801
auto *Def = Op->getDefiningRecipe();
28052802
if (Def && ExpressionRecipesAsSetOfUsers.contains(Def))
28062803
continue;
28072804
addOperand(Op);
2808-
if (OperandPlaceholders.find(Op) == OperandPlaceholders.end())
2809-
OperandPlaceholders[Op] = new VPValue();
2810-
LiveInPlaceholders.push_back(OperandPlaceholders[Op]);
2805+
VPValue *Tmp = new VPValue();
2806+
OperandPlaceholders[Op] = Tmp;
2807+
LiveInPlaceholders.push_back(Tmp);
28112808
}
28122809
}
28132810

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);
2819-
}
2820-
}
2811+
for (auto *R : ExpressionRecipes)
2812+
for (auto &Entry : OperandPlaceholders)
2813+
R->replaceUsesOfWith(Entry.first, Entry.second);
28212814
}
28222815

28232816
void VPExpressionRecipe::decompose() {
28242817
for (auto *R : ExpressionRecipes)
2818+
// Since the list could contain duplicates, make sure the recipe hasn't
2819+
// already been inserted.
28252820
if (!R->getParent())
28262821
R->insertBefore(this);
28272822

0 commit comments

Comments
 (0)