Skip to content

Commit b716d35

Browse files
authored
[VPlanPatternMatch] Introduce m_ConstantInt (#159558)
1 parent a46edff commit b716d35

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,33 @@ inline int_pred_ty<is_zero_int> m_ZeroInt() {
173173
/// For vectors, this includes constants with undefined elements.
174174
inline int_pred_ty<is_one> m_One() { return int_pred_ty<is_one>(); }
175175

176+
struct bind_const_int {
177+
uint64_t &Res;
178+
179+
bind_const_int(uint64_t &Res) : Res(Res) {}
180+
181+
bool match(VPValue *VPV) const {
182+
if (!VPV->isLiveIn())
183+
return false;
184+
Value *V = VPV->getLiveInIRValue();
185+
if (!V)
186+
return false;
187+
assert(!V->getType()->isVectorTy() && "Unexpected vector live-in");
188+
const auto *CI = dyn_cast<ConstantInt>(V);
189+
if (!CI)
190+
return false;
191+
if (auto C = CI->getValue().tryZExtValue()) {
192+
Res = *C;
193+
return true;
194+
}
195+
return false;
196+
}
197+
};
198+
199+
/// Match a plain integer constant no wider than 64-bits, capturing it if we
200+
/// match.
201+
inline bind_const_int m_ConstantInt(uint64_t &C) { return C; }
202+
176203
/// Matching combinators
177204
template <typename LTy, typename RTy> struct match_combine_or {
178205
LTy L;

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,11 +1592,12 @@ static bool tryToReplaceALMWithWideALM(VPlan &Plan, ElementCount VF,
15921592
m_ActiveLaneMask(m_VPValue(Index), m_VPValue(), m_VPValue()));
15931593
assert(Index && "Expected index from ActiveLaneMask instruction");
15941594

1595-
auto *II = dyn_cast<VPInstruction>(Index);
1596-
if (II && II->getOpcode() == VPInstruction::CanonicalIVIncrementForPart) {
1597-
auto Part = cast<ConstantInt>(II->getOperand(1)->getLiveInIRValue());
1598-
Phis[Part->getZExtValue()] = Phi;
1599-
} else
1595+
uint64_t Part;
1596+
if (match(Index,
1597+
m_VPInstruction<VPInstruction::CanonicalIVIncrementForPart>(
1598+
m_VPValue(), m_ConstantInt(Part))))
1599+
Phis[Part] = Phi;
1600+
else
16001601
// Anything other than a CanonicalIVIncrementForPart is part 0
16011602
Phis[0] = Phi;
16021603
}

0 commit comments

Comments
 (0)