Skip to content

Commit 148a835

Browse files
authored
[LV] Introduce m_One and improve (0|1)-match (NFC) (#157419)
1 parent cdedc81 commit 148a835

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9557,7 +9557,7 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
95579557
auto ResumePhiIter =
95589558
find_if(MainScalarPH->phis(), [VectorTC](VPRecipeBase &R) {
95599559
return match(&R, m_VPInstruction<Instruction::PHI>(m_Specific(VectorTC),
9560-
m_SpecificInt(0)));
9560+
m_ZeroInt()));
95619561
});
95629562
VPPhi *ResumePhi = nullptr;
95639563
if (ResumePhiIter == MainScalarPH->phis().end()) {

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,20 @@ struct is_zero_int {
149149
bool isValue(const APInt &C) const { return C.isZero(); }
150150
};
151151

152+
struct is_one {
153+
bool isValue(const APInt &C) const { return C.isOne(); }
154+
};
155+
152156
/// Match an integer 0 or a vector with all elements equal to 0.
153157
/// For vectors, this includes constants with undefined elements.
154158
inline int_pred_ty<is_zero_int> m_ZeroInt() {
155159
return int_pred_ty<is_zero_int>();
156160
}
157161

162+
/// Match an integer 1 or a vector with all elements equal to 1.
163+
/// For vectors, this includes constants with undefined elements.
164+
inline int_pred_ty<is_one> m_One() { return int_pred_ty<is_one>(); }
165+
158166
/// Matching combinators
159167
template <typename LTy, typename RTy> struct match_combine_or {
160168
LTy L;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ VPPartialReductionRecipe::computeCost(ElementCount VF,
328328
// Pick out opcode, type/ext information and use sub side effects from a widen
329329
// recipe.
330330
auto HandleWiden = [&](VPWidenRecipe *Widen) {
331-
if (match(Widen, m_Sub(m_SpecificInt(0), m_VPValue(Op)))) {
331+
if (match(Widen, m_Sub(m_ZeroInt(), m_VPValue(Op)))) {
332332
Widen = dyn_cast<VPWidenRecipe>(Op->getDefiningRecipe());
333333
}
334334
Opcode = Widen->getOpcode();

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11341134
return Def->replaceAllUsesWith(
11351135
Builder.createLogicalAnd(X, Builder.createLogicalAnd(Y, Z)));
11361136

1137-
if (match(Def, m_c_Mul(m_VPValue(A), m_SpecificInt(1))))
1137+
if (match(Def, m_c_Mul(m_VPValue(A), m_One())))
11381138
return Def->replaceAllUsesWith(A);
11391139

1140-
if (match(Def, m_c_Mul(m_VPValue(A), m_SpecificInt(0))))
1140+
if (match(Def, m_c_Mul(m_VPValue(A), m_ZeroInt())))
11411141
return Def->replaceAllUsesWith(R.getOperand(0) == A ? R.getOperand(1)
11421142
: R.getOperand(0));
11431143

@@ -1176,16 +1176,14 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11761176
}
11771177

11781178
// Remove redundant DerviedIVs, that is 0 + A * 1 -> A and 0 + 0 * x -> 0.
1179-
if ((match(Def,
1180-
m_DerivedIV(m_SpecificInt(0), m_VPValue(A), m_SpecificInt(1))) ||
1181-
match(Def,
1182-
m_DerivedIV(m_SpecificInt(0), m_SpecificInt(0), m_VPValue()))) &&
1179+
if ((match(Def, m_DerivedIV(m_ZeroInt(), m_VPValue(A), m_One())) ||
1180+
match(Def, m_DerivedIV(m_ZeroInt(), m_ZeroInt(), m_VPValue()))) &&
11831181
TypeInfo.inferScalarType(Def->getOperand(1)) ==
11841182
TypeInfo.inferScalarType(Def))
11851183
return Def->replaceAllUsesWith(Def->getOperand(1));
11861184

1187-
if (match(Def, m_VPInstruction<VPInstruction::WideIVStep>(
1188-
m_VPValue(X), m_SpecificInt(1)))) {
1185+
if (match(Def, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue(X),
1186+
m_One()))) {
11891187
Type *WideStepTy = TypeInfo.inferScalarType(Def);
11901188
if (TypeInfo.inferScalarType(X) != WideStepTy)
11911189
X = Builder.createWidenCast(Instruction::Trunc, X, WideStepTy);

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void UnrollState::unrollHeaderPHIByUF(VPHeaderPHIRecipe *R,
238238
if (Part != 1)
239239
continue;
240240
VPValue *StartV;
241-
if (match(VPI->getOperand(2), m_SpecificInt(1))) {
241+
if (match(VPI->getOperand(2), m_One())) {
242242
StartV = VPI->getOperand(1);
243243
} else {
244244
auto *C = VPI->clone();

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ bool vputils::isHeaderMask(const VPValue *V, VPlan &Plan) {
6565
VPValue *A, *B;
6666
using namespace VPlanPatternMatch;
6767

68-
if (match(V, m_ActiveLaneMask(m_VPValue(A), m_VPValue(B), m_SpecificInt(1))))
68+
if (match(V, m_ActiveLaneMask(m_VPValue(A), m_VPValue(B), m_One())))
6969
return B == Plan.getTripCount() &&
70-
(match(A, m_ScalarIVSteps(m_Specific(Plan.getCanonicalIV()),
71-
m_SpecificInt(1),
70+
(match(A, m_ScalarIVSteps(m_Specific(Plan.getCanonicalIV()), m_One(),
7271
m_Specific(&Plan.getVF()))) ||
7372
IsWideCanonicalIV(A));
7473

0 commit comments

Comments
 (0)