[llvm] [VPlan] Introduce VPlan::get(NullValue|AllOnes) (NFC) (PR #184085)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 06:58:14 PST 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/184085
>From cf41c227d54f440fc4396db2e2ea574dfc46d937 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 2 Mar 2026 09:37:26 +0000
Subject: [PATCH 1/2] [VPlan] Introduce VPlan::get(Zero|AllOnes) (NFC)
---
llvm/lib/Transforms/Vectorize/VPlan.h | 8 ++++++++
.../Transforms/Vectorize/VPlanTransforms.cpp | 17 +++++++++--------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 97e9c64d6481d..6e3fc610a587e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4774,6 +4774,14 @@ class VPlan {
/// Return a VPIRValue wrapping i1 false.
VPIRValue *getFalse() { return getConstantInt(1, 0); }
+ /// Return a VPIRValue wrapping the null value of type \p Ty.
+ VPIRValue *getNullValue(Type *Ty) { return getConstantInt(Ty, 0); }
+
+ /// Return a VPIRValue wrapping the AllOnes value of type \p Ty.
+ VPIRValue *getAllOnesValue(Type *Ty) {
+ return getConstantInt(APInt::getAllOnes(Ty->getIntegerBitWidth()));
+ }
+
/// Return a VPIRValue wrapping a ConstantInt with the given type and value.
VPIRValue *getConstantInt(Type *Ty, uint64_t Val, bool IsSigned = false) {
return getOrAddLiveIn(ConstantInt::get(Ty, Val, IsSigned));
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index c6aabe7f1ec0f..65c0702b6fb97 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1277,23 +1277,24 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
return;
}
- // x | 1 -> 1
+ // x | AllOnes -> AllOnes
if (match(Def, m_c_BinaryOr(m_VPValue(X), m_AllOnes())))
- return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
+ return Def->replaceAllUsesWith(
+ Plan->getAllOnesValue(TypeInfo.inferScalarType(Def)));
// x | 0 -> x
if (match(Def, m_c_BinaryOr(m_VPValue(X), m_ZeroInt())))
return Def->replaceAllUsesWith(X);
// x | !x -> AllOnes
- if (match(Def, m_c_BinaryOr(m_VPValue(X), m_Not(m_Deferred(X))))) {
- return Def->replaceAllUsesWith(Plan->getOrAddLiveIn(
- ConstantInt::getAllOnesValue(TypeInfo.inferScalarType(Def))));
- }
+ if (match(Def, m_c_BinaryOr(m_VPValue(X), m_Not(m_Deferred(X)))))
+ return Def->replaceAllUsesWith(
+ Plan->getAllOnesValue(TypeInfo.inferScalarType(Def)));
// x & 0 -> 0
if (match(Def, m_c_BinaryAnd(m_VPValue(X), m_ZeroInt())))
- return Def->replaceAllUsesWith(Def->getOperand(Def->getOperand(0) == X));
+ return Def->replaceAllUsesWith(
+ Plan->getNullValue(TypeInfo.inferScalarType(Def)));
// x & AllOnes -> x
if (match(Def, m_c_BinaryAnd(m_VPValue(X), m_AllOnes())))
@@ -1347,7 +1348,7 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
if (match(Def, m_c_Mul(m_VPValue(A), m_ZeroInt())))
return Def->replaceAllUsesWith(
- Def->getOperand(0) == A ? Def->getOperand(1) : Def->getOperand(0));
+ Plan->getNullValue(TypeInfo.inferScalarType(Def)));
const APInt *APC;
if (CanCreateNewRecipe && match(Def, m_c_Mul(m_VPValue(A), m_APInt(APC))) &&
>From 4d5ef08ef273f88045bac2f797cabe75a94eab78 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 2 Mar 2026 14:57:03 +0000
Subject: [PATCH 2/2] [VPlan] s/NullValue/Zero/
---
llvm/lib/Transforms/Vectorize/VPlan.h | 2 +-
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 6e3fc610a587e..5a75f28b21ba9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4775,7 +4775,7 @@ class VPlan {
VPIRValue *getFalse() { return getConstantInt(1, 0); }
/// Return a VPIRValue wrapping the null value of type \p Ty.
- VPIRValue *getNullValue(Type *Ty) { return getConstantInt(Ty, 0); }
+ VPIRValue *getZero(Type *Ty) { return getConstantInt(Ty, 0); }
/// Return a VPIRValue wrapping the AllOnes value of type \p Ty.
VPIRValue *getAllOnesValue(Type *Ty) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 65c0702b6fb97..c22bbf51c222c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1294,7 +1294,7 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
// x & 0 -> 0
if (match(Def, m_c_BinaryAnd(m_VPValue(X), m_ZeroInt())))
return Def->replaceAllUsesWith(
- Plan->getNullValue(TypeInfo.inferScalarType(Def)));
+ Plan->getZero(TypeInfo.inferScalarType(Def)));
// x & AllOnes -> x
if (match(Def, m_c_BinaryAnd(m_VPValue(X), m_AllOnes())))
@@ -1348,7 +1348,7 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
if (match(Def, m_c_Mul(m_VPValue(A), m_ZeroInt())))
return Def->replaceAllUsesWith(
- Plan->getNullValue(TypeInfo.inferScalarType(Def)));
+ Plan->getZero(TypeInfo.inferScalarType(Def)));
const APInt *APC;
if (CanCreateNewRecipe && match(Def, m_c_Mul(m_VPValue(A), m_APInt(APC))) &&
More information about the llvm-commits
mailing list