@@ -1057,54 +1057,51 @@ static VPValue *tryToFoldLiveIns(VPSingleDefRecipe &R,
10571057 return nullptr ;
10581058}
10591059
1060- // / Try to simplify recipe \p R.
1061- static void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1062- VPlan *Plan = R.getParent ()->getPlan ();
1063-
1064- auto *Def = dyn_cast<VPSingleDefRecipe>(&R);
1065- if (!Def)
1066- return ;
1060+ // / Try to simplify VPSingleDefRecipe \p Def.
1061+ static void simplifySingleDefRecipe (VPSingleDefRecipe &Def,
1062+ VPTypeAnalysis &TypeInfo) {
1063+ VPlan *Plan = Def.getParent ()->getPlan ();
10671064
10681065 // Simplification of live-in IR values for SingleDef recipes using
10691066 // InstSimplifyFolder.
10701067 const DataLayout &DL =
10711068 Plan->getScalarHeader ()->getIRBasicBlock ()->getDataLayout ();
1072- if (VPValue *V = tryToFoldLiveIns (* Def, Def-> operands (), DL, TypeInfo))
1073- return Def-> replaceAllUsesWith (V);
1069+ if (VPValue *V = tryToFoldLiveIns (Def, Def. operands (), DL, TypeInfo))
1070+ return Def. replaceAllUsesWith (V);
10741071
10751072 // Fold PredPHI LiveIn -> LiveIn.
1076- if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(&R )) {
1073+ if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(&Def )) {
10771074 VPValue *Op = PredPHI->getOperand (0 );
10781075 if (Op->isLiveIn ())
10791076 PredPHI->replaceAllUsesWith (Op);
10801077 }
10811078
1082- VPBuilder Builder (Def);
1079+ VPBuilder Builder (& Def);
10831080 VPValue *A;
1084- if (match (Def, m_Trunc (m_ZExtOrSExt (m_VPValue (A))))) {
1085- Type *TruncTy = TypeInfo.inferScalarType (Def);
1081+ if (match (& Def, m_Trunc (m_ZExtOrSExt (m_VPValue (A))))) {
1082+ Type *TruncTy = TypeInfo.inferScalarType (& Def);
10861083 Type *ATy = TypeInfo.inferScalarType (A);
10871084 if (TruncTy == ATy) {
1088- Def-> replaceAllUsesWith (A);
1085+ Def. replaceAllUsesWith (A);
10891086 } else {
10901087 // Don't replace a scalarizing recipe with a widened cast.
1091- if (isa<VPReplicateRecipe>(Def))
1088+ if (isa<VPReplicateRecipe>(& Def))
10921089 return ;
10931090 if (ATy->getScalarSizeInBits () < TruncTy->getScalarSizeInBits ()) {
10941091
1095- unsigned ExtOpcode = match (R .getOperand (0 ), m_SExt (m_VPValue ()))
1092+ unsigned ExtOpcode = match (Def .getOperand (0 ), m_SExt (m_VPValue ()))
10961093 ? Instruction::SExt
10971094 : Instruction::ZExt;
10981095 auto *Ext = Builder.createWidenCast (Instruction::CastOps (ExtOpcode), A,
10991096 TruncTy);
1100- if (auto *UnderlyingExt = R .getOperand (0 )->getUnderlyingValue ()) {
1097+ if (auto *UnderlyingExt = Def .getOperand (0 )->getUnderlyingValue ()) {
11011098 // UnderlyingExt has distinct return type, used to retain legacy cost.
11021099 Ext->setUnderlyingValue (UnderlyingExt);
11031100 }
1104- Def-> replaceAllUsesWith (Ext);
1101+ Def. replaceAllUsesWith (Ext);
11051102 } else if (ATy->getScalarSizeInBits () > TruncTy->getScalarSizeInBits ()) {
11061103 auto *Trunc = Builder.createWidenCast (Instruction::Trunc, A, TruncTy);
1107- Def-> replaceAllUsesWith (Trunc);
1104+ Def. replaceAllUsesWith (Trunc);
11081105 }
11091106 }
11101107#ifndef NDEBUG
@@ -1125,75 +1122,75 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11251122 // && (Y || Z) and (X || !X) into true. This requires queuing newly created
11261123 // recipes to be visited during simplification.
11271124 VPValue *X, *Y, *Z;
1128- if (match (Def,
1125+ if (match (& Def,
11291126 m_c_BinaryOr (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
11301127 m_LogicalAnd (m_Deferred (X), m_Not (m_Deferred (Y)))))) {
1131- Def-> replaceAllUsesWith (X);
1132- Def-> eraseFromParent ();
1128+ Def. replaceAllUsesWith (X);
1129+ Def. eraseFromParent ();
11331130 return ;
11341131 }
11351132
11361133 // x | 1 -> 1
1137- if (match (Def, m_c_BinaryOr (m_VPValue (X), m_AllOnes ())))
1138- return Def-> replaceAllUsesWith (Def-> getOperand (Def-> getOperand (0 ) == X));
1134+ if (match (& Def, m_c_BinaryOr (m_VPValue (X), m_AllOnes ())))
1135+ return Def. replaceAllUsesWith (Def. getOperand (Def. getOperand (0 ) == X));
11391136
11401137 // x | 0 -> x
1141- if (match (Def, m_c_BinaryOr (m_VPValue (X), m_ZeroInt ())))
1142- return Def-> replaceAllUsesWith (X);
1138+ if (match (& Def, m_c_BinaryOr (m_VPValue (X), m_ZeroInt ())))
1139+ return Def. replaceAllUsesWith (X);
11431140
11441141 // x & 0 -> 0
1145- if (match (Def, m_c_BinaryAnd (m_VPValue (X), m_ZeroInt ())))
1146- return Def-> replaceAllUsesWith (Def-> getOperand (Def-> getOperand (0 ) == X));
1142+ if (match (& Def, m_c_BinaryAnd (m_VPValue (X), m_ZeroInt ())))
1143+ return Def. replaceAllUsesWith (Def. getOperand (Def. getOperand (0 ) == X));
11471144
11481145 // x && false -> false
1149- if (match (Def, m_LogicalAnd (m_VPValue (X), m_False ())))
1150- return Def-> replaceAllUsesWith (Def-> getOperand (1 ));
1146+ if (match (& Def, m_LogicalAnd (m_VPValue (X), m_False ())))
1147+ return Def. replaceAllUsesWith (Def. getOperand (1 ));
11511148
11521149 // (x && y) || (x && z) -> x && (y || z)
1153- if (match (Def, m_c_BinaryOr (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
1154- m_LogicalAnd (m_Deferred (X), m_VPValue (Z)))) &&
1150+ if (match (& Def, m_c_BinaryOr (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
1151+ m_LogicalAnd (m_Deferred (X), m_VPValue (Z)))) &&
11551152 // Simplify only if one of the operands has one use to avoid creating an
11561153 // extra recipe.
1157- (!Def-> getOperand (0 )->hasMoreThanOneUniqueUser () ||
1158- !Def-> getOperand (1 )->hasMoreThanOneUniqueUser ()))
1159- return Def-> replaceAllUsesWith (
1154+ (!Def. getOperand (0 )->hasMoreThanOneUniqueUser () ||
1155+ !Def. getOperand (1 )->hasMoreThanOneUniqueUser ()))
1156+ return Def. replaceAllUsesWith (
11601157 Builder.createLogicalAnd (X, Builder.createOr (Y, Z)));
11611158
11621159 // x && !x -> 0
1163- if (match (&R , m_LogicalAnd (m_VPValue (X), m_Not (m_Deferred (X)))))
1164- return Def-> replaceAllUsesWith (Plan->getFalse ());
1160+ if (match (&Def , m_LogicalAnd (m_VPValue (X), m_Not (m_Deferred (X)))))
1161+ return Def. replaceAllUsesWith (Plan->getFalse ());
11651162
1166- if (match (Def, m_Select (m_VPValue (), m_VPValue (X), m_Deferred (X))))
1167- return Def-> replaceAllUsesWith (X);
1163+ if (match (& Def, m_Select (m_VPValue (), m_VPValue (X), m_Deferred (X))))
1164+ return Def. replaceAllUsesWith (X);
11681165
11691166 // select !c, x, y -> select c, y, x
11701167 VPValue *C;
1171- if (match (Def, m_Select (m_Not (m_VPValue (C)), m_VPValue (X), m_VPValue (Y)))) {
1172- Def-> setOperand (0 , C);
1173- Def-> setOperand (1 , Y);
1174- Def-> setOperand (2 , X);
1168+ if (match (& Def, m_Select (m_Not (m_VPValue (C)), m_VPValue (X), m_VPValue (Y)))) {
1169+ Def. setOperand (0 , C);
1170+ Def. setOperand (1 , Y);
1171+ Def. setOperand (2 , X);
11751172 return ;
11761173 }
11771174
11781175 // Reassociate (x && y) && z -> x && (y && z) if x has multiple users. With
11791176 // tail folding it is likely that x is a header mask and can be simplified
11801177 // further.
1181- if (match (Def, m_LogicalAnd (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
1182- m_VPValue (Z))) &&
1178+ if (match (& Def, m_LogicalAnd (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
1179+ m_VPValue (Z))) &&
11831180 X->hasMoreThanOneUniqueUser ())
1184- return Def-> replaceAllUsesWith (
1181+ return Def. replaceAllUsesWith (
11851182 Builder.createLogicalAnd (X, Builder.createLogicalAnd (Y, Z)));
11861183
1187- if (match (Def, m_c_Mul (m_VPValue (A), m_One ())))
1188- return Def-> replaceAllUsesWith (A);
1184+ if (match (& Def, m_c_Mul (m_VPValue (A), m_One ())))
1185+ return Def. replaceAllUsesWith (A);
11891186
1190- if (match (Def, m_c_Mul (m_VPValue (A), m_ZeroInt ())))
1191- return Def-> replaceAllUsesWith (R .getOperand (0 ) == A ? R .getOperand (1 )
1192- : R .getOperand (0 ));
1187+ if (match (& Def, m_c_Mul (m_VPValue (A), m_ZeroInt ())))
1188+ return Def. replaceAllUsesWith (Def .getOperand (0 ) == A ? Def .getOperand (1 )
1189+ : Def .getOperand (0 ));
11931190
1194- if (match (Def, m_Not (m_VPValue (A)))) {
1191+ if (match (& Def, m_Not (m_VPValue (A)))) {
11951192 if (match (A, m_Not (m_VPValue (A))))
1196- return Def-> replaceAllUsesWith (A);
1193+ return Def. replaceAllUsesWith (A);
11971194
11981195 // Try to fold Not into compares by adjusting the predicate in-place.
11991196 CmpPredicate Pred;
@@ -1218,71 +1215,71 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
12181215 }
12191216 // If Cmp doesn't have a debug location, use the one from the negation,
12201217 // to preserve the location.
1221- if (!Cmp->getDebugLoc () && R .getDebugLoc ())
1222- Cmp->setDebugLoc (R .getDebugLoc ());
1218+ if (!Cmp->getDebugLoc () && Def .getDebugLoc ())
1219+ Cmp->setDebugLoc (Def .getDebugLoc ());
12231220 }
12241221 }
12251222 }
12261223
12271224 // Remove redundant DerviedIVs, that is 0 + A * 1 -> A and 0 + 0 * x -> 0.
1228- if ((match (Def, m_DerivedIV (m_ZeroInt (), m_VPValue (A), m_One ())) ||
1229- match (Def, m_DerivedIV (m_ZeroInt (), m_ZeroInt (), m_VPValue ()))) &&
1230- TypeInfo.inferScalarType (Def-> getOperand (1 )) ==
1231- TypeInfo.inferScalarType (Def))
1232- return Def-> replaceAllUsesWith (Def-> getOperand (1 ));
1233-
1234- if (match (Def, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue (X),
1235- m_One ()))) {
1236- Type *WideStepTy = TypeInfo.inferScalarType (Def);
1225+ if ((match (& Def, m_DerivedIV (m_ZeroInt (), m_VPValue (A), m_One ())) ||
1226+ match (& Def, m_DerivedIV (m_ZeroInt (), m_ZeroInt (), m_VPValue ()))) &&
1227+ TypeInfo.inferScalarType (Def. getOperand (1 )) ==
1228+ TypeInfo.inferScalarType (& Def))
1229+ return Def. replaceAllUsesWith (Def. getOperand (1 ));
1230+
1231+ if (match (& Def, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue (X),
1232+ m_One ()))) {
1233+ Type *WideStepTy = TypeInfo.inferScalarType (& Def);
12371234 if (TypeInfo.inferScalarType (X) != WideStepTy)
12381235 X = Builder.createWidenCast (Instruction::Trunc, X, WideStepTy);
1239- Def-> replaceAllUsesWith (X);
1236+ Def. replaceAllUsesWith (X);
12401237 return ;
12411238 }
12421239
12431240 // For i1 vp.merges produced by AnyOf reductions:
12441241 // vp.merge true, (or x, y), x, evl -> vp.merge y, true, x, evl
1245- if (match (Def, m_Intrinsic<Intrinsic::vp_merge>(m_True (), m_VPValue (A),
1246- m_VPValue (X), m_VPValue ())) &&
1242+ if (match (& Def, m_Intrinsic<Intrinsic::vp_merge>(
1243+ m_True (), m_VPValue (A), m_VPValue (X), m_VPValue ())) &&
12471244 match (A, m_c_BinaryOr (m_Specific (X), m_VPValue (Y))) &&
1248- TypeInfo.inferScalarType (R .getVPSingleValue ())->isIntegerTy (1 )) {
1249- Def-> setOperand (1 , Def-> getOperand (0 ));
1250- Def-> setOperand (0 , Y);
1245+ TypeInfo.inferScalarType (Def .getVPSingleValue ())->isIntegerTy (1 )) {
1246+ Def. setOperand (1 , Def. getOperand (0 ));
1247+ Def. setOperand (0 , Y);
12511248 return ;
12521249 }
12531250
1254- if (auto *Phi = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(Def)) {
1251+ if (auto *Phi = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(& Def)) {
12551252 if (Phi->getOperand (0 ) == Phi->getOperand (1 ))
1256- Def ->replaceAllUsesWith (Phi->getOperand (0 ));
1253+ Phi ->replaceAllUsesWith (Phi->getOperand (0 ));
12571254 return ;
12581255 }
12591256
12601257 // Look through ExtractLastElement (BuildVector ....).
1261- if (match (&R , m_CombineOr (m_ExtractLastElement (m_BuildVector ()),
1262- m_ExtractLastLanePerPart (m_BuildVector ())))) {
1263- auto *BuildVector = cast<VPInstruction>(R .getOperand (0 ));
1264- Def-> replaceAllUsesWith (
1258+ if (match (&Def , m_CombineOr (m_ExtractLastElement (m_BuildVector ()),
1259+ m_ExtractLastLanePerPart (m_BuildVector ())))) {
1260+ auto *BuildVector = cast<VPInstruction>(Def .getOperand (0 ));
1261+ Def. replaceAllUsesWith (
12651262 BuildVector->getOperand (BuildVector->getNumOperands () - 1 ));
12661263 return ;
12671264 }
12681265
12691266 // Look through ExtractPenultimateElement (BuildVector ....).
1270- if (match (&R , m_VPInstruction<VPInstruction::ExtractPenultimateElement>(
1271- m_BuildVector ()))) {
1272- auto *BuildVector = cast<VPInstruction>(R .getOperand (0 ));
1273- Def-> replaceAllUsesWith (
1267+ if (match (&Def , m_VPInstruction<VPInstruction::ExtractPenultimateElement>(
1268+ m_BuildVector ()))) {
1269+ auto *BuildVector = cast<VPInstruction>(Def .getOperand (0 ));
1270+ Def. replaceAllUsesWith (
12741271 BuildVector->getOperand (BuildVector->getNumOperands () - 2 ));
12751272 return ;
12761273 }
12771274
12781275 uint64_t Idx;
1279- if (match (&R , m_ExtractElement (m_BuildVector (), m_ConstantInt (Idx)))) {
1280- auto *BuildVector = cast<VPInstruction>(R .getOperand (0 ));
1281- Def-> replaceAllUsesWith (BuildVector->getOperand (Idx));
1276+ if (match (&Def , m_ExtractElement (m_BuildVector (), m_ConstantInt (Idx)))) {
1277+ auto *BuildVector = cast<VPInstruction>(Def .getOperand (0 ));
1278+ Def. replaceAllUsesWith (BuildVector->getOperand (Idx));
12821279 return ;
12831280 }
12841281
1285- if (auto *Phi = dyn_cast<VPPhi>(Def)) {
1282+ if (auto *Phi = dyn_cast<VPPhi>(& Def)) {
12861283 if (Phi->getNumOperands () == 1 )
12871284 Phi->replaceAllUsesWith (Phi->getOperand (0 ));
12881285 return ;
@@ -1294,19 +1291,19 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
12941291 return ;
12951292
12961293 // Hoist an invariant increment Y of a phi X, by having X start at Y.
1297- if (match (Def, m_c_Add (m_VPValue (X), m_VPValue (Y))) && Y->isLiveIn () &&
1294+ if (match (& Def, m_c_Add (m_VPValue (X), m_VPValue (Y))) && Y->isLiveIn () &&
12981295 isa<VPPhi>(X)) {
12991296 auto *Phi = cast<VPPhi>(X);
1300- if (Phi->getOperand (1 ) != Def && match (Phi->getOperand (0 ), m_ZeroInt ()) &&
1301- Phi->getNumUsers () == 1 && (*Phi->user_begin () == &R )) {
1297+ if (Phi->getOperand (1 ) != & Def && match (Phi->getOperand (0 ), m_ZeroInt ()) &&
1298+ Phi->getNumUsers () == 1 && (*Phi->user_begin () == &Def )) {
13021299 Phi->setOperand (0 , Y);
1303- Def-> replaceAllUsesWith (Phi);
1300+ Def. replaceAllUsesWith (Phi);
13041301 return ;
13051302 }
13061303 }
13071304
13081305 // VPVectorPointer for part 0 can be replaced by their start pointer.
1309- if (auto *VecPtr = dyn_cast<VPVectorPointerRecipe>(&R )) {
1306+ if (auto *VecPtr = dyn_cast<VPVectorPointerRecipe>(&Def )) {
13101307 if (VecPtr->isFirstPart ()) {
13111308 VecPtr->replaceAllUsesWith (VecPtr->getOperand (0 ));
13121309 return ;
@@ -1315,43 +1312,43 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
13151312
13161313 // VPScalarIVSteps for part 0 can be replaced by their start value, if only
13171314 // the first lane is demanded.
1318- if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(Def)) {
1315+ if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(& Def)) {
13191316 if (Steps->isPart0 () && vputils::onlyFirstLaneUsed (Steps)) {
13201317 Steps->replaceAllUsesWith (Steps->getOperand (0 ));
13211318 return ;
13221319 }
13231320 }
13241321 // Simplify redundant ReductionStartVector recipes after unrolling.
13251322 VPValue *StartV;
1326- if (match (Def, m_VPInstruction<VPInstruction::ReductionStartVector>(
1327- m_VPValue (StartV), m_VPValue (), m_VPValue ()))) {
1328- Def-> replaceUsesWithIf (StartV, [](const VPUser &U, unsigned Idx) {
1323+ if (match (& Def, m_VPInstruction<VPInstruction::ReductionStartVector>(
1324+ m_VPValue (StartV), m_VPValue (), m_VPValue ()))) {
1325+ Def. replaceUsesWithIf (StartV, [](const VPUser &U, unsigned Idx) {
13291326 auto *PhiR = dyn_cast<VPReductionPHIRecipe>(&U);
13301327 return PhiR && PhiR->isInLoop ();
13311328 });
13321329 return ;
13331330 }
13341331
1335- if (match (Def,
1332+ if (match (& Def,
13361333 m_CombineOr (m_ExtractLastElement (m_Broadcast (m_VPValue (A))),
13371334 m_ExtractLastLanePerPart (m_Broadcast (m_VPValue (A)))))) {
1338- Def-> replaceAllUsesWith (A);
1335+ Def. replaceAllUsesWith (A);
13391336 return ;
13401337 }
13411338
1342- if (match (Def, m_CombineOr (m_ExtractLastElement (m_VPValue (A)),
1343- m_ExtractLastLanePerPart (m_VPValue (A)))) &&
1339+ if (match (& Def, m_CombineOr (m_ExtractLastElement (m_VPValue (A)),
1340+ m_ExtractLastLanePerPart (m_VPValue (A)))) &&
13441341 ((isa<VPInstruction>(A) && vputils::isSingleScalar (A)) ||
13451342 (isa<VPReplicateRecipe>(A) &&
13461343 cast<VPReplicateRecipe>(A)->isSingleScalar ())) &&
13471344 all_of (A->users (),
1348- [Def, A](VPUser *U) { return U->usesScalars (A) || Def == U; })) {
1349- return Def-> replaceAllUsesWith (A);
1345+ [& Def, A](VPUser *U) { return U->usesScalars (A) || & Def == U; })) {
1346+ return Def. replaceAllUsesWith (A);
13501347 }
13511348
13521349 if (Plan->getUF () == 1 &&
1353- match (Def, m_ExtractLastLanePerPart (m_VPValue (A)))) {
1354- return Def-> replaceAllUsesWith (
1350+ match (& Def, m_ExtractLastLanePerPart (m_VPValue (A)))) {
1351+ return Def. replaceAllUsesWith (
13551352 Builder.createNaryOp (VPInstruction::ExtractLastElement, {A}));
13561353 }
13571354}
@@ -1361,9 +1358,9 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan) {
13611358 Plan.getEntry ());
13621359 VPTypeAnalysis TypeInfo (Plan);
13631360 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
1364- for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
1365- simplifyRecipe (R, TypeInfo);
1366- }
1361+ for (VPRecipeBase &R : make_early_inc_range (*VPBB))
1362+ if ( auto *Def = dyn_cast<VPSingleDefRecipe>(&R))
1363+ simplifySingleDefRecipe (*Def, TypeInfo);
13671364 }
13681365}
13691366
0 commit comments