@@ -993,13 +993,13 @@ static Value *tryToFoldLiveIns(const VPRecipeBase &R, unsigned Opcode,
993
993
// / Try to simplify recipe \p R.
994
994
static void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
995
995
using namespace llvm ::VPlanPatternMatch;
996
+ VPlan *Plan = R.getParent ()->getPlan ();
996
997
997
998
// Simplification of live-in IR values for SingleDef recipes using
998
999
// InstSimplifyFolder.
999
1000
if (TypeSwitch<VPRecipeBase *, bool >(&R)
1000
1001
.Case <VPInstruction, VPWidenRecipe, VPWidenCastRecipe,
1001
1002
VPReplicateRecipe>([&](auto *I) {
1002
- VPlan *Plan = R.getParent ()->getPlan ();
1003
1003
const DataLayout &DL =
1004
1004
Plan->getScalarHeader ()->getIRBasicBlock ()->getDataLayout ();
1005
1005
Value *V = tryToFoldLiveIns (*I, I->getOpcode (), I->operands (), DL,
@@ -1013,25 +1013,13 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1013
1013
1014
1014
// Fold PredPHI constant -> constant.
1015
1015
if (auto *PredPHI = dyn_cast<VPPredInstPHIRecipe>(&R)) {
1016
- VPlan *Plan = R.getParent ()->getPlan ();
1017
1016
VPValue *Op = PredPHI->getOperand (0 );
1018
1017
if (!Op->isLiveIn () || !Op->getLiveInIRValue ())
1019
1018
return ;
1020
1019
if (auto *C = dyn_cast<Constant>(Op->getLiveInIRValue ()))
1021
1020
PredPHI->replaceAllUsesWith (Plan->getOrAddLiveIn (C));
1022
1021
}
1023
1022
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
-
1035
1023
VPValue *A;
1036
1024
if (match (&R, m_Trunc (m_ZExtOrSExt (m_VPValue (A))))) {
1037
1025
VPValue *Trunc = R.getVPSingleValue ();
@@ -1065,8 +1053,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1065
1053
#ifndef NDEBUG
1066
1054
// Verify that the cached type info is for both A and its users is still
1067
1055
// accurate by comparing it to freshly computed types.
1068
- VPTypeAnalysis TypeInfo2 (
1069
- R.getParent ()->getPlan ()->getCanonicalIV ()->getScalarType ());
1056
+ VPTypeAnalysis TypeInfo2 (Plan->getCanonicalIV ()->getScalarType ());
1070
1057
assert (TypeInfo.inferScalarType (A) == TypeInfo2.inferScalarType (A));
1071
1058
for (VPUser *U : A->users ()) {
1072
1059
auto *R = cast<VPRecipeBase>(U);
@@ -1151,6 +1138,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1151
1138
R.setOperand (0 , Y);
1152
1139
return ;
1153
1140
}
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
+ }
1154
1155
}
1155
1156
1156
1157
void VPlanTransforms::simplifyRecipes (VPlan &Plan, Type &CanonicalIVTy) {
0 commit comments