[llvm] b4743b2 - [VPlan] Introduce VPlan::get(Zero|AllOnes) (NFC) (#184085)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 01:47:10 PST 2026
Author: Ramkumar Ramachandra
Date: 2026-03-03T09:47:05Z
New Revision: b4743b2641b60fc0f577657be4ee884461e46e33
URL: https://github.com/llvm/llvm-project/commit/b4743b2641b60fc0f577657be4ee884461e46e33
DIFF: https://github.com/llvm/llvm-project/commit/b4743b2641b60fc0f577657be4ee884461e46e33.diff
LOG: [VPlan] Introduce VPlan::get(Zero|AllOnes) (NFC) (#184085)
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 97e9c64d6481d..5a75f28b21ba9 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 *getZero(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 b8329bb396ff6..877a8d77c810d 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->getZero(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->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