[llvm] 5f33a29 - [VPlan] Introduce VPConstant VPIRValue (NFC) (#207387)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 03:29:30 PDT 2026
Author: Ramkumar Ramachandra
Date: 2026-07-08T10:29:22Z
New Revision: 5f33a29bebe42a032a163a80e311d8ba305de3f6
URL: https://github.com/llvm/llvm-project/commit/5f33a29bebe42a032a163a80e311d8ba305de3f6
DIFF: https://github.com/llvm/llvm-project/commit/5f33a29bebe42a032a163a80e311d8ba305de3f6.diff
LOG: [VPlan] Introduce VPConstant VPIRValue (NFC) (#207387)
There a gap in the VPIRValue class hierarchy, where constant live-ins
are absent, when this is in fact a very common case. The motivation of
introducing this new class is to refine optimizations to account for the
fact that non-constant live-ins need broadcast.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
llvm/lib/Transforms/Vectorize/VPlanValue.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index da8152f820040..9848412dc9d4a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -2009,8 +2009,8 @@ static void narrowToSingleScalarRecipes(VPlan &Plan) {
return false;
// Non-constant live-ins require broadcasts, while constants do not
// need explicit broadcasts.
- auto *IRV = dyn_cast<VPIRValue>(Op);
- bool LiveInNeedsBroadcast = IRV && !isa<Constant>(IRV->getValue());
+ bool LiveInNeedsBroadcast =
+ isa<VPIRValue>(Op) && !isa<VPConstant>(Op);
auto *OpR = dyn_cast<VPReplicateRecipe>(Op);
return LiveInNeedsBroadcast || (OpR && OpR->isSingleScalar());
}))
@@ -5120,8 +5120,7 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
auto *VectorPreheader = Plan.getVectorPreheader();
for (VPValue *VPV : VPValues) {
- if (vputils::onlyScalarValuesUsed(VPV) ||
- (isa<VPIRValue>(VPV) && isa<Constant>(VPV->getLiveInIRValue())))
+ if (vputils::onlyScalarValuesUsed(VPV) || isa<VPConstant>(VPV))
continue;
// Add explicit broadcast at the insert point that dominates all users.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index 49b612ea41fca..738902519fe90 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -290,13 +290,27 @@ struct VPIRValue : public VPValue {
}
};
-/// An overlay on VPIRValue for VPValues that wrap a ConstantInt. Provides
-/// convenient accessors for the underlying constant.
-struct VPConstantInt : public VPIRValue {
- VPConstantInt(ConstantInt *CI) : VPIRValue(CI) {}
+/// An overlay on VPIRValue for VPValues that wrap a Constant. May be an
+/// integer, floating-point, or a vector constant.
+struct VPConstant : public VPIRValue {
+ VPConstant(Constant *C) : VPIRValue(C) {}
static bool classof(const VPValue *V) {
- return isa<VPIRValue>(V) && isa<ConstantInt>(V->getUnderlyingValue());
+ auto *IRV = dyn_cast<VPIRValue>(V);
+ return IRV && isa<Constant>(IRV->getValue());
+ }
+
+ const Constant *getConstant() const { return cast<Constant>(getValue()); }
+};
+
+/// An overlay on VPConstant for VPValues that wrap a ConstantInt. Provides
+/// convenient accessors for the underlying APInt.
+struct VPConstantInt : public VPConstant {
+ VPConstantInt(ConstantInt *CI) : VPConstant(CI) {}
+
+ static bool classof(const VPValue *V) {
+ auto *VPC = dyn_cast<VPConstant>(V);
+ return VPC && isa<ConstantInt>(VPC->getConstant());
}
bool isOne() const { return getAPInt().isOne(); }
More information about the llvm-commits
mailing list