Skip to content

Commit efae492

Browse files
committed
[VPlan] Add VPTypeAnalysis constructor taking a VPlan (NFC).
Add constructor that retrieves the scalar type from the trip count expression, if no canonical IV is available. Used in the verifier, in preparation for late verification, when the canonical IV has been dissolved.
1 parent 090f46d commit efae492

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ using namespace llvm;
2020

2121
#define DEBUG_TYPE "vplan"
2222

23+
VPTypeAnalysis::VPTypeAnalysis(const VPlan &Plan)
24+
: Ctx(Plan.getScalarHeader()->getIRBasicBlock()->getContext()) {
25+
if (auto LoopRegion = Plan.getVectorLoopRegion()) {
26+
if (const auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(
27+
&LoopRegion->getEntryBasicBlock()->front())) {
28+
CanonicalIVTy = CanIV->getScalarType();
29+
return;
30+
}
31+
}
32+
33+
// If there's no canonical IV, retrieve the type from the trip count
34+
// expression.
35+
auto *TC = Plan.getTripCount();
36+
if (TC->isLiveIn()) {
37+
CanonicalIVTy = TC->getLiveInIRValue()->getType();
38+
return;
39+
}
40+
CanonicalIVTy = cast<VPExpandSCEVRecipe>(TC)->getSCEV()->getType();
41+
}
42+
2343
Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
2444
Type *ResTy = inferScalarType(R->getIncomingValue(0));
2545
for (unsigned I = 1, E = R->getNumIncomingValues(); I != E; ++I) {

llvm/lib/Transforms/Vectorize/VPlanAnalysis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class VPTypeAnalysis {
5858
VPTypeAnalysis(Type *CanonicalIVTy)
5959
: CanonicalIVTy(CanonicalIVTy), Ctx(CanonicalIVTy->getContext()) {}
6060

61+
VPTypeAnalysis(const VPlan &Plan);
62+
6163
/// Infer the type of \p V. Returns the scalar type of \p V.
6264
Type *inferScalarType(const VPValue *V);
6365

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ bool VPlanVerifier::verify(const VPlan &Plan) {
455455
bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
456456
VPDominatorTree VPDT;
457457
VPDT.recalculate(const_cast<VPlan &>(Plan));
458-
VPTypeAnalysis TypeInfo(
459-
const_cast<VPlan &>(Plan).getCanonicalIV()->getScalarType());
458+
VPTypeAnalysis TypeInfo(Plan);
460459
VPlanVerifier Verifier(VPDT, TypeInfo);
461460
return Verifier.verify(Plan);
462461
}

0 commit comments

Comments
 (0)