[llvm] [LV] Keep duplicate recipes in VPExpressionRecipe (PR #156976)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 22 05:56:24 PDT 2025
================
@@ -2797,25 +2796,42 @@ VPExpressionRecipe::VPExpressionRecipe(
R->removeFromParent();
}
+ // Keep track of how many instances of each recipe occur in the recipe list
+ SmallMapVector<VPSingleDefRecipe *, unsigned, 4> ExpressionRecipeCounts;
+ for (auto *R : ExpressionRecipes) {
+ auto *F = ExpressionRecipeCounts.find(R);
+ if (F == ExpressionRecipeCounts.end())
+ ExpressionRecipeCounts.insert(std::make_pair(R, 1));
+ else
+ F->second++;
+ }
+
// Internalize all external operands to the expression recipes. To do so,
// 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.
for (auto *R : ExpressionRecipes) {
+ auto *F = ExpressionRecipeCounts.find(R);
+ F->second--;
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());
+ auto *Tmp = new VPValue();
+ LiveInPlaceholders.push_back(Tmp);
+ // Only modify this recipe's operands if it's the last time it occurs in
+ // the recipe list
+ if (F->second == 0)
+ R->setOperand(Idx, Tmp);
----------------
sdesmalen-arm wrote:
If you were to keep a map of `Op -> new VPValue()` nodes, then you can just do:
```
LiveInPlaceholders.push_back(new VPValue());
MyMap[Op] = LiveInPlaceholders.back();
```
and then have a loop at the end to replace all values of `Op` by their LiveInPlaceholder (i.e. `new VPValue()`) values for each `R` in `ExpressionRecipes`.
That would also fix the potential issue I mentioned above, where same input operand is shared by multiple recipes passed to the expression.
https://github.com/llvm/llvm-project/pull/156976
More information about the llvm-commits
mailing list