[llvm] 3b474bc - [VPlan] Use VPSingleDef in simplifyRecipe (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 1 07:33:08 PDT 2025
Author: Florian Hahn
Date: 2025-06-01T15:32:02+01:00
New Revision: 3b474bc510d6975fd1d09f5408a82dfb4daaea30
URL: https://github.com/llvm/llvm-project/commit/3b474bc510d6975fd1d09f5408a82dfb4daaea30
DIFF: https://github.com/llvm/llvm-project/commit/3b474bc510d6975fd1d09f5408a82dfb4daaea30.diff
LOG: [VPlan] Use VPSingleDef in simplifyRecipe (NFC).
All simplifications are applied to VPSingleDefRecipes. Check for them
early to skip unnecessary work and remove a number of getVPSingleValue
calls.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index b214498229e52..5b42a9056b69e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -995,6 +995,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
using namespace llvm::VPlanPatternMatch;
VPlan *Plan = R.getParent()->getPlan();
+ auto *Def = dyn_cast<VPSingleDefRecipe>(&R);
+ if (!Def)
+ return;
+
// Simplification of live-in IR values for SingleDef recipes using
// InstSimplifyFolder.
if (TypeSwitch<VPRecipeBase *, bool>(&R)
@@ -1021,15 +1025,14 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
}
VPValue *A;
- if (match(&R, m_Trunc(m_ZExtOrSExt(m_VPValue(A))))) {
- VPValue *Trunc = R.getVPSingleValue();
- Type *TruncTy = TypeInfo.inferScalarType(Trunc);
+ if (match(Def, m_Trunc(m_ZExtOrSExt(m_VPValue(A))))) {
+ Type *TruncTy = TypeInfo.inferScalarType(Def);
Type *ATy = TypeInfo.inferScalarType(A);
if (TruncTy == ATy) {
- Trunc->replaceAllUsesWith(A);
+ Def->replaceAllUsesWith(A);
} else {
// Don't replace a scalarizing recipe with a widened cast.
- if (isa<VPReplicateRecipe>(&R))
+ if (isa<VPReplicateRecipe>(Def))
return;
if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) {
@@ -1043,11 +1046,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
VPC->setUnderlyingValue(UnderlyingExt);
}
VPC->insertBefore(&R);
- Trunc->replaceAllUsesWith(VPC);
+ Def->replaceAllUsesWith(VPC);
} else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) {
auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy);
VPC->insertBefore(&R);
- Trunc->replaceAllUsesWith(VPC);
+ Def->replaceAllUsesWith(VPC);
}
}
#ifndef NDEBUG
@@ -1068,31 +1071,31 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
// && (Y || Z) and (X || !X) into true. This requires queuing newly created
// recipes to be visited during simplification.
VPValue *X, *Y;
- if (match(&R,
+ if (match(Def,
m_c_BinaryOr(m_LogicalAnd(m_VPValue(X), m_VPValue(Y)),
m_LogicalAnd(m_Deferred(X), m_Not(m_Deferred(Y)))))) {
- R.getVPSingleValue()->replaceAllUsesWith(X);
- R.eraseFromParent();
+ Def->replaceAllUsesWith(X);
+ Def->eraseFromParent();
return;
}
// OR x, 1 -> 1.
- if (match(&R, m_c_BinaryOr(m_VPValue(X), m_AllOnes()))) {
- R.getVPSingleValue()->replaceAllUsesWith(
- R.getOperand(0) == X ? R.getOperand(1) : R.getOperand(0));
- R.eraseFromParent();
+ if (match(Def, m_c_BinaryOr(m_VPValue(X), m_AllOnes()))) {
+ Def->replaceAllUsesWith(Def->getOperand(0) == X ? Def->getOperand(1)
+ : Def->getOperand(0));
+ Def->eraseFromParent();
return;
}
- if (match(&R, m_Select(m_VPValue(), m_VPValue(X), m_Deferred(X))))
- return R.getVPSingleValue()->replaceAllUsesWith(X);
+ if (match(Def, m_Select(m_VPValue(), m_VPValue(X), m_Deferred(X))))
+ return Def->replaceAllUsesWith(X);
- if (match(&R, m_c_Mul(m_VPValue(A), m_SpecificInt(1))))
- return R.getVPSingleValue()->replaceAllUsesWith(A);
+ if (match(Def, m_c_Mul(m_VPValue(A), m_SpecificInt(1))))
+ return Def->replaceAllUsesWith(A);
- if (match(&R, m_Not(m_VPValue(A)))) {
+ if (match(Def, m_Not(m_VPValue(A)))) {
if (match(A, m_Not(m_VPValue(A))))
- return R.getVPSingleValue()->replaceAllUsesWith(A);
+ return Def->replaceAllUsesWith(A);
// Try to fold Not into compares by adjusting the predicate in-place.
if (isa<VPWidenRecipe>(A) && A->getNumUsers() == 1) {
@@ -1101,7 +1104,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
WideCmp->getOpcode() == Instruction::FCmp) {
WideCmp->setPredicate(
CmpInst::getInversePredicate(WideCmp->getPredicate()));
- R.getVPSingleValue()->replaceAllUsesWith(WideCmp);
+ Def->replaceAllUsesWith(WideCmp);
// If WideCmp doesn't have a debug location, use the one from the
// negation, to preserve the location.
if (!WideCmp->getDebugLoc() && R.getDebugLoc())
@@ -1111,31 +1114,31 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
}
// Remove redundant DerviedIVs, that is 0 + A * 1 -> A and 0 + 0 * x -> 0.
- if ((match(&R,
+ if ((match(Def,
m_DerivedIV(m_SpecificInt(0), m_VPValue(A), m_SpecificInt(1))) ||
- match(&R,
+ match(Def,
m_DerivedIV(m_SpecificInt(0), m_SpecificInt(0), m_VPValue()))) &&
- TypeInfo.inferScalarType(R.getOperand(1)) ==
- TypeInfo.inferScalarType(R.getVPSingleValue()))
- return R.getVPSingleValue()->replaceAllUsesWith(R.getOperand(1));
+ TypeInfo.inferScalarType(Def->getOperand(1)) ==
+ TypeInfo.inferScalarType(Def))
+ return Def->replaceAllUsesWith(Def->getOperand(1));
- if (match(&R, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue(X),
- m_SpecificInt(1)))) {
- Type *WideStepTy = TypeInfo.inferScalarType(R.getVPSingleValue());
+ if (match(Def, m_VPInstruction<VPInstruction::WideIVStep>(
+ m_VPValue(X), m_SpecificInt(1)))) {
+ Type *WideStepTy = TypeInfo.inferScalarType(Def);
if (TypeInfo.inferScalarType(X) != WideStepTy)
- X = VPBuilder(&R).createWidenCast(Instruction::Trunc, X, WideStepTy);
- R.getVPSingleValue()->replaceAllUsesWith(X);
+ X = VPBuilder(Def).createWidenCast(Instruction::Trunc, X, WideStepTy);
+ Def->replaceAllUsesWith(X);
return;
}
// For i1 vp.merges produced by AnyOf reductions:
// vp.merge true, (or x, y), x, evl -> vp.merge y, true, x, evl
- if (match(&R, m_Intrinsic<Intrinsic::vp_merge>(m_True(), m_VPValue(A),
- m_VPValue(X), m_VPValue())) &&
+ if (match(Def, m_Intrinsic<Intrinsic::vp_merge>(m_True(), m_VPValue(A),
+ m_VPValue(X), m_VPValue())) &&
match(A, m_c_BinaryOr(m_Specific(X), m_VPValue(Y))) &&
TypeInfo.inferScalarType(R.getVPSingleValue())->isIntegerTy(1)) {
- R.setOperand(1, R.getOperand(0));
- R.setOperand(0, Y);
+ Def->setOperand(1, Def->getOperand(0));
+ Def->setOperand(0, Y);
return;
}
@@ -1146,7 +1149,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
// VPScalarIVSteps for part 0 can be replaced by their start value, if only
// the first lane is demanded.
- if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(&R)) {
+ if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(Def)) {
if (Steps->isPart0() && vputils::onlyFirstLaneUsed(Steps)) {
Steps->replaceAllUsesWith(Steps->getOperand(0));
return;
More information about the llvm-commits
mailing list