[llvm] efae492 - [VPlan] Add VPTypeAnalysis constructor taking a VPlan (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 15 14:19:43 PDT 2025
Author: Florian Hahn
Date: 2025-05-15T22:19:36+01:00
New Revision: efae492ad1ba80764ec4a85f5622a8713646f970
URL: https://github.com/llvm/llvm-project/commit/efae492ad1ba80764ec4a85f5622a8713646f970
DIFF: https://github.com/llvm/llvm-project/commit/efae492ad1ba80764ec4a85f5622a8713646f970.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index c86815c84d8d9..b07f9a386b534 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -20,6 +20,26 @@ using namespace llvm;
#define DEBUG_TYPE "vplan"
+VPTypeAnalysis::VPTypeAnalysis(const VPlan &Plan)
+ : Ctx(Plan.getScalarHeader()->getIRBasicBlock()->getContext()) {
+ if (auto LoopRegion = Plan.getVectorLoopRegion()) {
+ if (const auto *CanIV = dyn_cast<VPCanonicalIVPHIRecipe>(
+ &LoopRegion->getEntryBasicBlock()->front())) {
+ CanonicalIVTy = CanIV->getScalarType();
+ return;
+ }
+ }
+
+ // If there's no canonical IV, retrieve the type from the trip count
+ // expression.
+ auto *TC = Plan.getTripCount();
+ if (TC->isLiveIn()) {
+ CanonicalIVTy = TC->getLiveInIRValue()->getType();
+ return;
+ }
+ CanonicalIVTy = cast<VPExpandSCEVRecipe>(TC)->getSCEV()->getType();
+}
+
Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
Type *ResTy = inferScalarType(R->getIncomingValue(0));
for (unsigned I = 1, E = R->getNumIncomingValues(); I != E; ++I) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
index cc21870bee2e3..941e13959c23b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h
@@ -58,6 +58,8 @@ class VPTypeAnalysis {
VPTypeAnalysis(Type *CanonicalIVTy)
: CanonicalIVTy(CanonicalIVTy), Ctx(CanonicalIVTy->getContext()) {}
+ VPTypeAnalysis(const VPlan &Plan);
+
/// Infer the type of \p V. Returns the scalar type of \p V.
Type *inferScalarType(const VPValue *V);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 1e7e039a18d56..75fc76321db2d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -455,8 +455,7 @@ bool VPlanVerifier::verify(const VPlan &Plan) {
bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
VPDominatorTree VPDT;
VPDT.recalculate(const_cast<VPlan &>(Plan));
- VPTypeAnalysis TypeInfo(
- const_cast<VPlan &>(Plan).getCanonicalIV()->getScalarType());
+ VPTypeAnalysis TypeInfo(Plan);
VPlanVerifier Verifier(VPDT, TypeInfo);
return Verifier.verify(Plan);
}
More information about the llvm-commits
mailing list