Skip to content

Commit b739a3c

Browse files
authored
[VPlan] Add m_Deferred. NFC (llvm#133736)
This copies over the implementation of m_Deferred which allows matching values that were bound in the pattern, and uses it for the (X && Y) || (X && !Y) -> X simplifcation.
1 parent c632466 commit b739a3c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ struct specificval_ty {
6666

6767
inline specificval_ty m_Specific(const VPValue *VPV) { return VPV; }
6868

69+
/// Stores a reference to the VPValue *, not the VPValue * itself,
70+
/// thus can be used in commutative matchers.
71+
struct deferredval_ty {
72+
VPValue *const &Val;
73+
74+
deferredval_ty(VPValue *const &V) : Val(V) {}
75+
76+
bool match(VPValue *const V) const { return V == Val; }
77+
};
78+
79+
/// Like m_Specific(), but works if the specific value to match is determined
80+
/// as part of the same match() expression. For example:
81+
/// m_Mul(m_VPValue(X), m_Specific(X)) is incorrect, because m_Specific() will
82+
/// bind X before the pattern match starts.
83+
/// m_Mul(m_VPValue(X), m_Deferred(X)) is correct, and will check against
84+
/// whichever value m_VPValue(X) populated.
85+
inline deferredval_ty m_Deferred(VPValue *const &V) { return V; }
86+
6987
/// Match a specified integer value or vector of all elements of that
7088
/// value. \p BitWidth optionally specifies the bitwidth the matched constant
7189
/// must have. If it is 0, the matched constant can have any bitwidth.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10531053
// TODO: Split up into simpler, modular combines: (X && Y) || (X && Z) into X
10541054
// && (Y || Z) and (X || !X) into true. This requires queuing newly created
10551055
// recipes to be visited during simplification.
1056-
VPValue *X, *Y, *X1, *Y1;
1056+
VPValue *X, *Y;
10571057
if (match(&R,
10581058
m_c_BinaryOr(m_LogicalAnd(m_VPValue(X), m_VPValue(Y)),
1059-
m_LogicalAnd(m_VPValue(X1), m_Not(m_VPValue(Y1))))) &&
1060-
X == X1 && Y == Y1) {
1059+
m_LogicalAnd(m_Deferred(X), m_Not(m_Deferred(Y)))))) {
10611060
R.getVPSingleValue()->replaceAllUsesWith(X);
10621061
R.eraseFromParent();
10631062
return;

0 commit comments

Comments
 (0)