Skip to content

Commit 33bbce5

Browse files
committed
[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.
1 parent 573545c commit 33bbce5

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -993,13 +993,13 @@ static Value *tryToFoldLiveIns(const VPRecipeBase &R, unsigned Opcode,
993993
/// Try to simplify recipe \p R.
994994
static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
995995
using namespace llvm::VPlanPatternMatch;
996+
VPlan *Plan = R.getParent()->getPlan();
996997

997998
// Simplification of live-in IR values for SingleDef recipes using
998999
// InstSimplifyFolder.
9991000
if (TypeSwitch<VPRecipeBase *, bool>(&R)
10001001
.Case<VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
10011002
VPReplicateRecipe>([&](auto *I) {
1002-
VPlan *Plan = R.getParent()->getPlan();
10031003
const DataLayout &DL =
10041004
Plan->getScalarHeader()->getIRBasicBlock()->getDataLayout();
10051005
Value *V = tryToFoldLiveIns(*I, I->getOpcode(), I->operands(), DL,
@@ -1013,25 +1013,13 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10131013

10141014
// Fold PredPHI constant -> constant.
10151015
if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(&R)) {
1016-
VPlan *Plan = R.getParent()->getPlan();
10171016
VPValue *Op = PredPHI->getOperand(0);
10181017
if (!Op->isLiveIn() || !Op->getLiveInIRValue())
10191018
return;
10201019
if (auto *C = dyn_cast<Constant>(Op->getLiveInIRValue()))
10211020
PredPHI->replaceAllUsesWith(Plan->getOrAddLiveIn(C));
10221021
}
10231022

1024-
// VPScalarIVSteps can only be simplified after unrolling. VPScalarIVSteps for
1025-
// part 0 can be replaced by their start value, if only the first lane is
1026-
// demanded.
1027-
if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(&R)) {
1028-
if (Steps->getParent()->getPlan()->isUnrolled() && Steps->isPart0() &&
1029-
vputils::onlyFirstLaneUsed(Steps)) {
1030-
Steps->replaceAllUsesWith(Steps->getOperand(0));
1031-
return;
1032-
}
1033-
}
1034-
10351023
VPValue *A;
10361024
if (match(&R, m_Trunc(m_ZExtOrSExt(m_VPValue(A))))) {
10371025
VPValue *Trunc = R.getVPSingleValue();
@@ -1065,8 +1053,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10651053
#ifndef NDEBUG
10661054
// Verify that the cached type info is for both A and its users is still
10671055
// accurate by comparing it to freshly computed types.
1068-
VPTypeAnalysis TypeInfo2(
1069-
R.getParent()->getPlan()->getCanonicalIV()->getScalarType());
1056+
VPTypeAnalysis TypeInfo2(Plan->getCanonicalIV()->getScalarType());
10701057
assert(TypeInfo.inferScalarType(A) == TypeInfo2.inferScalarType(A));
10711058
for (VPUser *U : A->users()) {
10721059
auto *R = cast<VPRecipeBase>(U);
@@ -1151,6 +1138,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11511138
R.setOperand(0, Y);
11521139
return;
11531140
}
1141+
1142+
// Some simplifications can only be applied after unrolling. Perform them
1143+
// below.
1144+
if (!Plan->isUnrolled())
1145+
return;
1146+
1147+
// VPScalarIVSteps for part 0 can be replaced by their start value, if only
1148+
// the first lane is demanded.
1149+
if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(&R)) {
1150+
if (Steps->isPart0() && vputils::onlyFirstLaneUsed(Steps)) {
1151+
Steps->replaceAllUsesWith(Steps->getOperand(0));
1152+
return;
1153+
}
1154+
}
11541155
}
11551156

11561157
void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {

0 commit comments

Comments
 (0)