Skip to content

Commit f5c591d

Browse files
committed
Remove erased type from VTypeAnalysis cache, move assertion into all simplifications
1 parent 32ddc99 commit f5c591d

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.
@@ -1024,13 +1012,28 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {
10241012
VPRecipeBase *R = Worklist.pop_back_val();
10251013
if (VPValue *Result = simplifyRecipe(*R, TypeInfo)) {
10261014
R->getVPSingleValue()->replaceAllUsesWith(Result);
1015+
TypeInfo.erase(R->getVPSingleValue());
10271016
R->eraseFromParent();
10281017
if (VPRecipeBase *ResultR = Result->getDefiningRecipe())
10291018
Worklist.insert(ResultR);
10301019
for (VPUser *U : Result->users())
10311020
if (auto *UR = dyn_cast<VPRecipeBase>(U))
10321021
if (UR != R)
10331022
Worklist.insert(UR);
1023+
1024+
#ifndef NDEBUG
1025+
// Verify that the cached type info is for both Result and its users is
1026+
// still accurate by comparing it to freshly computed types.
1027+
VPTypeAnalysis TypeInfo2(&CanonicalIVTy);
1028+
assert(TypeInfo.inferScalarType(Result) ==
1029+
TypeInfo2.inferScalarType(Result));
1030+
for (VPUser *U : Result->users()) {
1031+
auto *R = cast<VPRecipeBase>(U);
1032+
for (VPValue *VPV : R->definedValues())
1033+
assert(TypeInfo.inferScalarType(VPV) ==
1034+
TypeInfo2.inferScalarType(VPV));
1035+
}
1036+
#endif
10341037
}
10351038
}
10361039
}

0 commit comments

Comments
 (0)