[llvm] 33bbce5 - [VPlan] Get plan once in simplifyRecipe (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 1 04:46:42 PDT 2025
Author: Florian Hahn
Date: 2025-06-01T12:46:08+01:00
New Revision: 33bbce5e34fcc0bf85f327258e7da356ab8b8978
URL: https://github.com/llvm/llvm-project/commit/33bbce5e34fcc0bf85f327258e7da356ab8b8978
DIFF: https://github.com/llvm/llvm-project/commit/33bbce5e34fcc0bf85f327258e7da356ab8b8978.diff
LOG: [VPlan] Get plan once in simplifyRecipe (NFC).
Also check once if the plan is unrolled at the end, to make it easier to
add more transforms that apply after unrolling.
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 6ee7df5dd9875..b214498229e52 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -993,13 +993,13 @@ static Value *tryToFoldLiveIns(const VPRecipeBase &R, unsigned Opcode,
/// Try to simplify recipe \p R.
static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
using namespace llvm::VPlanPatternMatch;
+ VPlan *Plan = R.getParent()->getPlan();
// Simplification of live-in IR values for SingleDef recipes using
// InstSimplifyFolder.
if (TypeSwitch<VPRecipeBase *, bool>(&R)
.Case<VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
VPReplicateRecipe>([&](auto *I) {
- VPlan *Plan = R.getParent()->getPlan();
const DataLayout &DL =
Plan->getScalarHeader()->getIRBasicBlock()->getDataLayout();
Value *V = tryToFoldLiveIns(*I, I->getOpcode(), I->operands(), DL,
@@ -1013,7 +1013,6 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
// Fold PredPHI constant -> constant.
if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(&R)) {
- VPlan *Plan = R.getParent()->getPlan();
VPValue *Op = PredPHI->getOperand(0);
if (!Op->isLiveIn() || !Op->getLiveInIRValue())
return;
@@ -1021,17 +1020,6 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
PredPHI->replaceAllUsesWith(Plan->getOrAddLiveIn(C));
}
- // VPScalarIVSteps can only be simplified after unrolling. 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 (Steps->getParent()->getPlan()->isUnrolled() && Steps->isPart0() &&
- vputils::onlyFirstLaneUsed(Steps)) {
- Steps->replaceAllUsesWith(Steps->getOperand(0));
- return;
- }
- }
-
VPValue *A;
if (match(&R, m_Trunc(m_ZExtOrSExt(m_VPValue(A))))) {
VPValue *Trunc = R.getVPSingleValue();
@@ -1065,8 +1053,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
#ifndef NDEBUG
// Verify that the cached type info is for both A and its users is still
// accurate by comparing it to freshly computed types.
- VPTypeAnalysis TypeInfo2(
- R.getParent()->getPlan()->getCanonicalIV()->getScalarType());
+ VPTypeAnalysis TypeInfo2(Plan->getCanonicalIV()->getScalarType());
assert(TypeInfo.inferScalarType(A) == TypeInfo2.inferScalarType(A));
for (VPUser *U : A->users()) {
auto *R = cast<VPRecipeBase>(U);
@@ -1151,6 +1138,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
R.setOperand(0, Y);
return;
}
+
+ // Some simplifications can only be applied after unrolling. Perform them
+ // below.
+ if (!Plan->isUnrolled())
+ return;
+
+ // 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 (Steps->isPart0() && vputils::onlyFirstLaneUsed(Steps)) {
+ Steps->replaceAllUsesWith(Steps->getOperand(0));
+ return;
+ }
+ }
}
void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {
More information about the llvm-commits
mailing list