Skip to content

Commit d79d9e4

Browse files
Mel-ChenDebadri Basak
authored andcommitted
[VPlanTransform] Specialize simplifyRecipe for VPSingleDefRecipe pointer. nfc (llvm#165568)
The function simplifyRecipe now takes a VPSingleDefRecipe pointer since it only simplifies single-def recipes for now.
1 parent bb29c8e commit d79d9e4

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,13 +1063,9 @@ static VPValue *tryToFoldLiveIns(VPSingleDefRecipe &R,
10631063
return nullptr;
10641064
}
10651065

1066-
/// Try to simplify recipe \p R.
1067-
static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1068-
VPlan *Plan = R.getParent()->getPlan();
1069-
1070-
auto *Def = dyn_cast<VPSingleDefRecipe>(&R);
1071-
if (!Def)
1072-
return;
1066+
/// Try to simplify VPSingleDefRecipe \p Def.
1067+
static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
1068+
VPlan *Plan = Def->getParent()->getPlan();
10731069

10741070
// Simplification of live-in IR values for SingleDef recipes using
10751071
// InstSimplifyFolder.
@@ -1079,7 +1075,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10791075
return Def->replaceAllUsesWith(V);
10801076

10811077
// Fold PredPHI LiveIn -> LiveIn.
1082-
if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(&R)) {
1078+
if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(Def)) {
10831079
VPValue *Op = PredPHI->getOperand(0);
10841080
if (Op->isLiveIn())
10851081
PredPHI->replaceAllUsesWith(Op);
@@ -1098,12 +1094,12 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10981094
return;
10991095
if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) {
11001096

1101-
unsigned ExtOpcode = match(R.getOperand(0), m_SExt(m_VPValue()))
1097+
unsigned ExtOpcode = match(Def->getOperand(0), m_SExt(m_VPValue()))
11021098
? Instruction::SExt
11031099
: Instruction::ZExt;
11041100
auto *Ext = Builder.createWidenCast(Instruction::CastOps(ExtOpcode), A,
11051101
TruncTy);
1106-
if (auto *UnderlyingExt = R.getOperand(0)->getUnderlyingValue()) {
1102+
if (auto *UnderlyingExt = Def->getOperand(0)->getUnderlyingValue()) {
11071103
// UnderlyingExt has distinct return type, used to retain legacy cost.
11081104
Ext->setUnderlyingValue(UnderlyingExt);
11091105
}
@@ -1166,7 +1162,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11661162
Builder.createLogicalAnd(X, Builder.createOr(Y, Z)));
11671163

11681164
// x && !x -> 0
1169-
if (match(&R, m_LogicalAnd(m_VPValue(X), m_Not(m_Deferred(X)))))
1165+
if (match(Def, m_LogicalAnd(m_VPValue(X), m_Not(m_Deferred(X)))))
11701166
return Def->replaceAllUsesWith(Plan->getFalse());
11711167

11721168
if (match(Def, m_Select(m_VPValue(), m_VPValue(X), m_Deferred(X))))
@@ -1194,8 +1190,8 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11941190
return Def->replaceAllUsesWith(A);
11951191

11961192
if (match(Def, m_c_Mul(m_VPValue(A), m_ZeroInt())))
1197-
return Def->replaceAllUsesWith(R.getOperand(0) == A ? R.getOperand(1)
1198-
: R.getOperand(0));
1193+
return Def->replaceAllUsesWith(
1194+
Def->getOperand(0) == A ? Def->getOperand(1) : Def->getOperand(0));
11991195

12001196
if (match(Def, m_Not(m_VPValue(A)))) {
12011197
if (match(A, m_Not(m_VPValue(A))))
@@ -1224,8 +1220,8 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
12241220
}
12251221
// If Cmp doesn't have a debug location, use the one from the negation,
12261222
// to preserve the location.
1227-
if (!Cmp->getDebugLoc() && R.getDebugLoc())
1228-
Cmp->setDebugLoc(R.getDebugLoc());
1223+
if (!Cmp->getDebugLoc() && Def->getDebugLoc())
1224+
Cmp->setDebugLoc(Def->getDebugLoc());
12291225
}
12301226
}
12311227
}
@@ -1251,44 +1247,44 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
12511247
if (match(Def, m_Intrinsic<Intrinsic::vp_merge>(m_True(), m_VPValue(A),
12521248
m_VPValue(X), m_VPValue())) &&
12531249
match(A, m_c_BinaryOr(m_Specific(X), m_VPValue(Y))) &&
1254-
TypeInfo.inferScalarType(R.getVPSingleValue())->isIntegerTy(1)) {
1250+
TypeInfo.inferScalarType(Def)->isIntegerTy(1)) {
12551251
Def->setOperand(1, Def->getOperand(0));
12561252
Def->setOperand(0, Y);
12571253
return;
12581254
}
12591255

12601256
if (auto *Phi = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(Def)) {
12611257
if (Phi->getOperand(0) == Phi->getOperand(1))
1262-
Def->replaceAllUsesWith(Phi->getOperand(0));
1258+
Phi->replaceAllUsesWith(Phi->getOperand(0));
12631259
return;
12641260
}
12651261

12661262
// Look through ExtractLastElement (BuildVector ....).
1267-
if (match(&R, m_CombineOr(m_ExtractLastElement(m_BuildVector()),
1268-
m_ExtractLastLanePerPart(m_BuildVector())))) {
1269-
auto *BuildVector = cast<VPInstruction>(R.getOperand(0));
1263+
if (match(Def, m_CombineOr(m_ExtractLastElement(m_BuildVector()),
1264+
m_ExtractLastLanePerPart(m_BuildVector())))) {
1265+
auto *BuildVector = cast<VPInstruction>(Def->getOperand(0));
12701266
Def->replaceAllUsesWith(
12711267
BuildVector->getOperand(BuildVector->getNumOperands() - 1));
12721268
return;
12731269
}
12741270

12751271
// Look through ExtractPenultimateElement (BuildVector ....).
1276-
if (match(&R, m_VPInstruction<VPInstruction::ExtractPenultimateElement>(
1277-
m_BuildVector()))) {
1278-
auto *BuildVector = cast<VPInstruction>(R.getOperand(0));
1272+
if (match(Def, m_VPInstruction<VPInstruction::ExtractPenultimateElement>(
1273+
m_BuildVector()))) {
1274+
auto *BuildVector = cast<VPInstruction>(Def->getOperand(0));
12791275
Def->replaceAllUsesWith(
12801276
BuildVector->getOperand(BuildVector->getNumOperands() - 2));
12811277
return;
12821278
}
12831279

12841280
uint64_t Idx;
1285-
if (match(&R, m_ExtractElement(m_BuildVector(), m_ConstantInt(Idx)))) {
1286-
auto *BuildVector = cast<VPInstruction>(R.getOperand(0));
1281+
if (match(Def, m_ExtractElement(m_BuildVector(), m_ConstantInt(Idx)))) {
1282+
auto *BuildVector = cast<VPInstruction>(Def->getOperand(0));
12871283
Def->replaceAllUsesWith(BuildVector->getOperand(Idx));
12881284
return;
12891285
}
12901286

1291-
if (match(Def, m_BuildVector()) && all_equal(R.operands())) {
1287+
if (match(Def, m_BuildVector()) && all_equal(Def->operands())) {
12921288
Def->replaceAllUsesWith(
12931289
Builder.createNaryOp(VPInstruction::Broadcast, Def->getOperand(0)));
12941290
return;
@@ -1310,15 +1306,15 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
13101306
isa<VPPhi>(X)) {
13111307
auto *Phi = cast<VPPhi>(X);
13121308
if (Phi->getOperand(1) != Def && match(Phi->getOperand(0), m_ZeroInt()) &&
1313-
Phi->getNumUsers() == 1 && (*Phi->user_begin() == &R)) {
1309+
Phi->getNumUsers() == 1 && (*Phi->user_begin() == Def)) {
13141310
Phi->setOperand(0, Y);
13151311
Def->replaceAllUsesWith(Phi);
13161312
return;
13171313
}
13181314
}
13191315

13201316
// VPVectorPointer for part 0 can be replaced by their start pointer.
1321-
if (auto *VecPtr = dyn_cast<VPVectorPointerRecipe>(&R)) {
1317+
if (auto *VecPtr = dyn_cast<VPVectorPointerRecipe>(Def)) {
13221318
if (VecPtr->isFirstPart()) {
13231319
VecPtr->replaceAllUsesWith(VecPtr->getOperand(0));
13241320
return;
@@ -1373,9 +1369,9 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan) {
13731369
Plan.getEntry());
13741370
VPTypeAnalysis TypeInfo(Plan);
13751371
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
1376-
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
1377-
simplifyRecipe(R, TypeInfo);
1378-
}
1372+
for (VPRecipeBase &R : make_early_inc_range(*VPBB))
1373+
if (auto *Def = dyn_cast<VPSingleDefRecipe>(&R))
1374+
simplifyRecipe(Def, TypeInfo);
13791375
}
13801376
}
13811377

0 commit comments

Comments
 (0)