Skip to content

Commit e51abd6

Browse files
committed
Defer deleting recipes till after transformation
1 parent f152006 commit e51abd6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ void VPlanTransforms::addActiveLaneMask(
14461446
static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14471447
using namespace llvm::VPlanPatternMatch;
14481448
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
1449+
VPTypeAnalysis TypeInfo(CanonicalIVType);
14491450
LLVMContext &Ctx = CanonicalIVType->getContext();
14501451
SmallVector<VPValue *> HeaderMasks = collectAllHeaderMasks(Plan);
14511452

@@ -1454,6 +1455,8 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14541455
R->setOperand(1, &EVL);
14551456
}
14561457

1458+
SmallVector<VPRecipeBase *> ToErase;
1459+
14571460
for (VPValue *HeaderMask : collectAllHeaderMasks(Plan)) {
14581461
for (VPUser *U : collectUsersRecursively(HeaderMask)) {
14591462
auto *CurRecipe = cast<VPRecipeBase>(U);
@@ -1462,10 +1465,6 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
14621465
return HeaderMask == OrigMask ? nullptr : OrigMask;
14631466
};
14641467

1465-
// Don't preseve the type info cache across loop iterations since
1466-
// CurRecipe will be erased and invalidate it.
1467-
VPTypeAnalysis TypeInfo(CanonicalIVType);
1468-
14691468
VPRecipeBase *NewRecipe =
14701469
TypeSwitch<VPRecipeBase *, VPRecipeBase *>(CurRecipe)
14711470
.Case<VPWidenLoadRecipe>([&](VPWidenLoadRecipe *L) {
@@ -1568,10 +1567,17 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
15681567
VPValue *CurVPV = CurRecipe->getVPSingleValue();
15691568
CurVPV->replaceAllUsesWith(NewRecipe->getVPSingleValue());
15701569
}
1571-
CurRecipe->eraseFromParent();
1570+
// Defer erasing recipes till the end so that we don't invalidate the
1571+
// VPTypeAnalysis cache
1572+
ToErase.push_back(CurRecipe);
15721573
}
1573-
recursivelyDeleteDeadRecipes(HeaderMask);
15741574
}
1575+
1576+
for (VPRecipeBase *R : ToErase)
1577+
R->eraseFromParent();
1578+
1579+
for (VPValue *HeaderMask : collectAllHeaderMasks(Plan))
1580+
recursivelyDeleteDeadRecipes(HeaderMask);
15751581
}
15761582

15771583
/// Add a VPEVLBasedIVPHIRecipe and related recipes to \p Plan and

0 commit comments

Comments
 (0)