@@ -995,6 +995,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
995995 using namespace llvm ::VPlanPatternMatch;
996996 VPlan *Plan = R.getParent ()->getPlan ();
997997
998+ auto *Def = dyn_cast<VPSingleDefRecipe>(&R);
999+ if (!Def)
1000+ return ;
1001+
9981002 // Simplification of live-in IR values for SingleDef recipes using
9991003 // InstSimplifyFolder.
10001004 if (TypeSwitch<VPRecipeBase *, bool >(&R)
@@ -1021,15 +1025,14 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10211025 }
10221026
10231027 VPValue *A;
1024- if (match (&R, m_Trunc (m_ZExtOrSExt (m_VPValue (A))))) {
1025- VPValue *Trunc = R.getVPSingleValue ();
1026- Type *TruncTy = TypeInfo.inferScalarType (Trunc);
1028+ if (match (Def, m_Trunc (m_ZExtOrSExt (m_VPValue (A))))) {
1029+ Type *TruncTy = TypeInfo.inferScalarType (Def);
10271030 Type *ATy = TypeInfo.inferScalarType (A);
10281031 if (TruncTy == ATy) {
1029- Trunc ->replaceAllUsesWith (A);
1032+ Def ->replaceAllUsesWith (A);
10301033 } else {
10311034 // Don't replace a scalarizing recipe with a widened cast.
1032- if (isa<VPReplicateRecipe>(&R ))
1035+ if (isa<VPReplicateRecipe>(Def ))
10331036 return ;
10341037 if (ATy->getScalarSizeInBits () < TruncTy->getScalarSizeInBits ()) {
10351038
@@ -1043,11 +1046,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10431046 VPC->setUnderlyingValue (UnderlyingExt);
10441047 }
10451048 VPC->insertBefore (&R);
1046- Trunc ->replaceAllUsesWith (VPC);
1049+ Def ->replaceAllUsesWith (VPC);
10471050 } else if (ATy->getScalarSizeInBits () > TruncTy->getScalarSizeInBits ()) {
10481051 auto *VPC = new VPWidenCastRecipe (Instruction::Trunc, A, TruncTy);
10491052 VPC->insertBefore (&R);
1050- Trunc ->replaceAllUsesWith (VPC);
1053+ Def ->replaceAllUsesWith (VPC);
10511054 }
10521055 }
10531056#ifndef NDEBUG
@@ -1068,31 +1071,31 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10681071 // && (Y || Z) and (X || !X) into true. This requires queuing newly created
10691072 // recipes to be visited during simplification.
10701073 VPValue *X, *Y;
1071- if (match (&R ,
1074+ if (match (Def ,
10721075 m_c_BinaryOr (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
10731076 m_LogicalAnd (m_Deferred (X), m_Not (m_Deferred (Y)))))) {
1074- R. getVPSingleValue () ->replaceAllUsesWith (X);
1075- R. eraseFromParent ();
1077+ Def ->replaceAllUsesWith (X);
1078+ Def-> eraseFromParent ();
10761079 return ;
10771080 }
10781081
10791082 // OR x, 1 -> 1.
1080- if (match (&R , m_c_BinaryOr (m_VPValue (X), m_AllOnes ()))) {
1081- R. getVPSingleValue ()-> replaceAllUsesWith (
1082- R. getOperand ( 0 ) == X ? R. getOperand ( 1 ) : R. getOperand (0 ));
1083- R. eraseFromParent ();
1083+ if (match (Def , m_c_BinaryOr (m_VPValue (X), m_AllOnes ()))) {
1084+ Def-> replaceAllUsesWith (Def-> getOperand ( 0 ) == X ? Def-> getOperand ( 1 )
1085+ : Def-> getOperand (0 ));
1086+ Def-> eraseFromParent ();
10841087 return ;
10851088 }
10861089
1087- if (match (&R , m_Select (m_VPValue (), m_VPValue (X), m_Deferred (X))))
1088- return R. getVPSingleValue () ->replaceAllUsesWith (X);
1090+ if (match (Def , m_Select (m_VPValue (), m_VPValue (X), m_Deferred (X))))
1091+ return Def ->replaceAllUsesWith (X);
10891092
1090- if (match (&R , m_c_Mul (m_VPValue (A), m_SpecificInt (1 ))))
1091- return R. getVPSingleValue () ->replaceAllUsesWith (A);
1093+ if (match (Def , m_c_Mul (m_VPValue (A), m_SpecificInt (1 ))))
1094+ return Def ->replaceAllUsesWith (A);
10921095
1093- if (match (&R , m_Not (m_VPValue (A)))) {
1096+ if (match (Def , m_Not (m_VPValue (A)))) {
10941097 if (match (A, m_Not (m_VPValue (A))))
1095- return R. getVPSingleValue () ->replaceAllUsesWith (A);
1098+ return Def ->replaceAllUsesWith (A);
10961099
10971100 // Try to fold Not into compares by adjusting the predicate in-place.
10981101 if (isa<VPWidenRecipe>(A) && A->getNumUsers () == 1 ) {
@@ -1101,7 +1104,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11011104 WideCmp->getOpcode () == Instruction::FCmp) {
11021105 WideCmp->setPredicate (
11031106 CmpInst::getInversePredicate (WideCmp->getPredicate ()));
1104- R. getVPSingleValue () ->replaceAllUsesWith (WideCmp);
1107+ Def ->replaceAllUsesWith (WideCmp);
11051108 // If WideCmp doesn't have a debug location, use the one from the
11061109 // negation, to preserve the location.
11071110 if (!WideCmp->getDebugLoc () && R.getDebugLoc ())
@@ -1111,31 +1114,31 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11111114 }
11121115
11131116 // Remove redundant DerviedIVs, that is 0 + A * 1 -> A and 0 + 0 * x -> 0.
1114- if ((match (&R ,
1117+ if ((match (Def ,
11151118 m_DerivedIV (m_SpecificInt (0 ), m_VPValue (A), m_SpecificInt (1 ))) ||
1116- match (&R ,
1119+ match (Def ,
11171120 m_DerivedIV (m_SpecificInt (0 ), m_SpecificInt (0 ), m_VPValue ()))) &&
1118- TypeInfo.inferScalarType (R. getOperand (1 )) ==
1119- TypeInfo.inferScalarType (R. getVPSingleValue () ))
1120- return R. getVPSingleValue () ->replaceAllUsesWith (R. getOperand (1 ));
1121+ TypeInfo.inferScalarType (Def-> getOperand (1 )) ==
1122+ TypeInfo.inferScalarType (Def ))
1123+ return Def ->replaceAllUsesWith (Def-> getOperand (1 ));
11211124
1122- if (match (&R , m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue (X),
1123- m_SpecificInt (1 )))) {
1124- Type *WideStepTy = TypeInfo.inferScalarType (R. getVPSingleValue () );
1125+ if (match (Def , m_VPInstruction<VPInstruction::WideIVStep>(
1126+ m_VPValue (X), m_SpecificInt (1 )))) {
1127+ Type *WideStepTy = TypeInfo.inferScalarType (Def );
11251128 if (TypeInfo.inferScalarType (X) != WideStepTy)
1126- X = VPBuilder (&R ).createWidenCast (Instruction::Trunc, X, WideStepTy);
1127- R. getVPSingleValue () ->replaceAllUsesWith (X);
1129+ X = VPBuilder (Def ).createWidenCast (Instruction::Trunc, X, WideStepTy);
1130+ Def ->replaceAllUsesWith (X);
11281131 return ;
11291132 }
11301133
11311134 // For i1 vp.merges produced by AnyOf reductions:
11321135 // vp.merge true, (or x, y), x, evl -> vp.merge y, true, x, evl
1133- if (match (&R , m_Intrinsic<Intrinsic::vp_merge>(m_True (), m_VPValue (A),
1134- m_VPValue (X), m_VPValue ())) &&
1136+ if (match (Def , m_Intrinsic<Intrinsic::vp_merge>(m_True (), m_VPValue (A),
1137+ m_VPValue (X), m_VPValue ())) &&
11351138 match (A, m_c_BinaryOr (m_Specific (X), m_VPValue (Y))) &&
11361139 TypeInfo.inferScalarType (R.getVPSingleValue ())->isIntegerTy (1 )) {
1137- R. setOperand (1 , R. getOperand (0 ));
1138- R. setOperand (0 , Y);
1140+ Def-> setOperand (1 , Def-> getOperand (0 ));
1141+ Def-> setOperand (0 , Y);
11391142 return ;
11401143 }
11411144
@@ -1146,7 +1149,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11461149
11471150 // VPScalarIVSteps for part 0 can be replaced by their start value, if only
11481151 // the first lane is demanded.
1149- if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(&R )) {
1152+ if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(Def )) {
11501153 if (Steps->isPart0 () && vputils::onlyFirstLaneUsed (Steps)) {
11511154 Steps->replaceAllUsesWith (Steps->getOperand (0 ));
11521155 return ;
0 commit comments