Skip to content

Commit 4e05ab9

Browse files
committed
Remove erased type from VTypeAnalysis cache, move assertion into all simplifications
1 parent 43e9f29 commit 4e05ab9

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

llvm/lib/Transforms/Vectorize/VPlanAnalysis.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class VPTypeAnalysis {
6363

6464
/// Return the LLVMContext used by the analysis.
6565
LLVMContext &getContext() { return Ctx; }
66+
67+
/// Remove \p V from the cache. You must call this after a value is erased.
68+
void erase(VPValue *V) { CachedTypes.erase(V); }
6669
};
6770

6871
// Collect a VPlan's ephemeral recipes (those used only by an assume).

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -966,18 +966,6 @@ static VPValue *simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
966966
return VPC;
967967
}
968968
}
969-
#ifndef NDEBUG
970-
// Verify that the cached type info is for both A and its users is still
971-
// accurate by comparing it to freshly computed types.
972-
VPTypeAnalysis TypeInfo2(
973-
R.getParent()->getPlan()->getCanonicalIV()->getScalarType());
974-
assert(TypeInfo.inferScalarType(A) == TypeInfo2.inferScalarType(A));
975-
for (VPUser *U : A->users()) {
976-
auto *R = cast<VPRecipeBase>(U);
977-
for (VPValue *VPV : R->definedValues())
978-
assert(TypeInfo.inferScalarType(VPV) == TypeInfo2.inferScalarType(VPV));
979-
}
980-
#endif
981969
}
982970

983971
// Simplify (X && Y) || (X && !Y) -> X.
@@ -1021,13 +1009,28 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {
10211009
VPRecipeBase *R = Worklist.pop_back_val();
10221010
if (VPValue *Result = simplifyRecipe(*R, TypeInfo)) {
10231011
R->getVPSingleValue()->replaceAllUsesWith(Result);
1012+
TypeInfo.erase(R->getVPSingleValue());
10241013
R->eraseFromParent();
10251014
if (VPRecipeBase *ResultR = Result->getDefiningRecipe())
10261015
Worklist.insert(ResultR);
10271016
for (VPUser *U : Result->users())
10281017
if (auto *UR = dyn_cast<VPRecipeBase>(U))
10291018
if (UR != R)
10301019
Worklist.insert(UR);
1020+
1021+
#ifndef NDEBUG
1022+
// Verify that the cached type info is for both Result and its users is
1023+
// still accurate by comparing it to freshly computed types.
1024+
VPTypeAnalysis TypeInfo2(&CanonicalIVTy);
1025+
assert(TypeInfo.inferScalarType(Result) ==
1026+
TypeInfo2.inferScalarType(Result));
1027+
for (VPUser *U : Result->users()) {
1028+
auto *R = cast<VPRecipeBase>(U);
1029+
for (VPValue *VPV : R->definedValues())
1030+
assert(TypeInfo.inferScalarType(VPV) ==
1031+
TypeInfo2.inferScalarType(VPV));
1032+
}
1033+
#endif
10311034
}
10321035
}
10331036
}

0 commit comments

Comments
 (0)