[llvm] [LV] Keep duplicate recipes in VPExpressionRecipe (PR #156976)
Sam Tebbs via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 26 03:42:04 PDT 2025
================
@@ -2801,21 +2800,36 @@ VPExpressionRecipe::VPExpressionRecipe(
// create new temporary VPValues for all operands defined by a recipe outside
// the expression. The original operands are added as operands of the
// VPExpressionRecipe itself.
+
+ // This map caches the temporary placeholders so duplicates aren't created in
+ // the case that recipes share operands.
+ SmallMapVector<VPValue *, VPValue *, 4> OperandPlaceholders;
+
for (auto *R : ExpressionRecipes) {
for (const auto &[Idx, Op] : enumerate(R->operands())) {
auto *Def = Op->getDefiningRecipe();
if (Def && ExpressionRecipesAsSetOfUsers.contains(Def))
continue;
addOperand(Op);
- LiveInPlaceholders.push_back(new VPValue());
- R->setOperand(Idx, LiveInPlaceholders.back());
+ if (OperandPlaceholders.find(Op) == OperandPlaceholders.end())
+ OperandPlaceholders[Op] = new VPValue();
+ LiveInPlaceholders.push_back(OperandPlaceholders[Op]);
+ }
+ }
+
+ for (auto *R : ExpressionRecipes) {
+ for (const auto &[Idx, Op] : enumerate(R->operands())) {
+ auto *Entry = OperandPlaceholders.find(Op);
+ if (Entry != OperandPlaceholders.end())
+ R->setOperand(Idx, Entry->second);
}
}
----------------
SamTebbs33 wrote:
Much better, thanks.
https://github.com/llvm/llvm-project/pull/156976
More information about the llvm-commits
mailing list