@@ -995,6 +995,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
995
995
using namespace llvm ::VPlanPatternMatch;
996
996
VPlan *Plan = R.getParent ()->getPlan ();
997
997
998
+ auto *Def = dyn_cast<VPSingleDefRecipe>(&R);
999
+ if (!Def)
1000
+ return ;
1001
+
998
1002
// Simplification of live-in IR values for SingleDef recipes using
999
1003
// InstSimplifyFolder.
1000
1004
if (TypeSwitch<VPRecipeBase *, bool >(&R)
@@ -1021,15 +1025,14 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1021
1025
}
1022
1026
1023
1027
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);
1027
1030
Type *ATy = TypeInfo.inferScalarType (A);
1028
1031
if (TruncTy == ATy) {
1029
- Trunc ->replaceAllUsesWith (A);
1032
+ Def ->replaceAllUsesWith (A);
1030
1033
} else {
1031
1034
// Don't replace a scalarizing recipe with a widened cast.
1032
- if (isa<VPReplicateRecipe>(&R ))
1035
+ if (isa<VPReplicateRecipe>(Def ))
1033
1036
return ;
1034
1037
if (ATy->getScalarSizeInBits () < TruncTy->getScalarSizeInBits ()) {
1035
1038
@@ -1043,11 +1046,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1043
1046
VPC->setUnderlyingValue (UnderlyingExt);
1044
1047
}
1045
1048
VPC->insertBefore (&R);
1046
- Trunc ->replaceAllUsesWith (VPC);
1049
+ Def ->replaceAllUsesWith (VPC);
1047
1050
} else if (ATy->getScalarSizeInBits () > TruncTy->getScalarSizeInBits ()) {
1048
1051
auto *VPC = new VPWidenCastRecipe (Instruction::Trunc, A, TruncTy);
1049
1052
VPC->insertBefore (&R);
1050
- Trunc ->replaceAllUsesWith (VPC);
1053
+ Def ->replaceAllUsesWith (VPC);
1051
1054
}
1052
1055
}
1053
1056
#ifndef NDEBUG
@@ -1068,31 +1071,31 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1068
1071
// && (Y || Z) and (X || !X) into true. This requires queuing newly created
1069
1072
// recipes to be visited during simplification.
1070
1073
VPValue *X, *Y;
1071
- if (match (&R ,
1074
+ if (match (Def ,
1072
1075
m_c_BinaryOr (m_LogicalAnd (m_VPValue (X), m_VPValue (Y)),
1073
1076
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 ();
1076
1079
return ;
1077
1080
}
1078
1081
1079
1082
// 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 ();
1084
1087
return ;
1085
1088
}
1086
1089
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);
1089
1092
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);
1092
1095
1093
- if (match (&R , m_Not (m_VPValue (A)))) {
1096
+ if (match (Def , m_Not (m_VPValue (A)))) {
1094
1097
if (match (A, m_Not (m_VPValue (A))))
1095
- return R. getVPSingleValue () ->replaceAllUsesWith (A);
1098
+ return Def ->replaceAllUsesWith (A);
1096
1099
1097
1100
// Try to fold Not into compares by adjusting the predicate in-place.
1098
1101
if (isa<VPWidenRecipe>(A) && A->getNumUsers () == 1 ) {
@@ -1101,7 +1104,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1101
1104
WideCmp->getOpcode () == Instruction::FCmp) {
1102
1105
WideCmp->setPredicate (
1103
1106
CmpInst::getInversePredicate (WideCmp->getPredicate ()));
1104
- R. getVPSingleValue () ->replaceAllUsesWith (WideCmp);
1107
+ Def ->replaceAllUsesWith (WideCmp);
1105
1108
// If WideCmp doesn't have a debug location, use the one from the
1106
1109
// negation, to preserve the location.
1107
1110
if (!WideCmp->getDebugLoc () && R.getDebugLoc ())
@@ -1111,31 +1114,31 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1111
1114
}
1112
1115
1113
1116
// Remove redundant DerviedIVs, that is 0 + A * 1 -> A and 0 + 0 * x -> 0.
1114
- if ((match (&R ,
1117
+ if ((match (Def ,
1115
1118
m_DerivedIV (m_SpecificInt (0 ), m_VPValue (A), m_SpecificInt (1 ))) ||
1116
- match (&R ,
1119
+ match (Def ,
1117
1120
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 ));
1121
1124
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 );
1125
1128
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);
1128
1131
return ;
1129
1132
}
1130
1133
1131
1134
// For i1 vp.merges produced by AnyOf reductions:
1132
1135
// 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 ())) &&
1135
1138
match (A, m_c_BinaryOr (m_Specific (X), m_VPValue (Y))) &&
1136
1139
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);
1139
1142
return ;
1140
1143
}
1141
1144
@@ -1146,7 +1149,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
1146
1149
1147
1150
// VPScalarIVSteps for part 0 can be replaced by their start value, if only
1148
1151
// the first lane is demanded.
1149
- if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(&R )) {
1152
+ if (auto *Steps = dyn_cast<VPScalarIVStepsRecipe>(Def )) {
1150
1153
if (Steps->isPart0 () && vputils::onlyFirstLaneUsed (Steps)) {
1151
1154
Steps->replaceAllUsesWith (Steps->getOperand (0 ));
1152
1155
return ;
0 commit comments