Skip to content

Commit a96b78c

Browse files
authored
[SCEVPatternMatch] Add signed cst match; use in LV (NFC) (#154568)
Add a m_scev_SpecificSInt for matching a sign-extended value, and use it to improve some code in LoopVectorize.
1 parent 5c36fb3 commit a96b78c

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ struct is_specific_cst {
116116
/// Match an SCEV constant with a plain unsigned integer.
117117
inline cst_pred_ty<is_specific_cst> m_scev_SpecificInt(uint64_t V) { return V; }
118118

119+
struct is_specific_signed_cst {
120+
int64_t CV;
121+
is_specific_signed_cst(int64_t C) : CV(C) {}
122+
bool isValue(const APInt &C) const { return C.trySExtValue() == CV; }
123+
};
124+
125+
/// Match an SCEV constant with a plain signed integer (sign-extended value will
126+
/// be matched)
127+
inline cst_pred_ty<is_specific_signed_cst> m_scev_SpecificSInt(int64_t V) {
128+
return V;
129+
}
130+
119131
struct bind_cst_ty {
120132
const APInt *&CR;
121133

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,21 +5918,11 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) {
59185918
// TODO: do we need to figure out the cost of an extract to get the
59195919
// first lane? Or do we hope that it will be folded away?
59205920
ScalarEvolution *SE = PSE.getSE();
5921-
const auto *SAR =
5922-
dyn_cast<SCEVAddRecExpr>(SE->getSCEV(ScalarParam));
5923-
5924-
if (!SAR || SAR->getLoop() != TheLoop) {
5921+
if (!match(SE->getSCEV(ScalarParam),
5922+
m_scev_AffineAddRec(
5923+
m_SCEV(), m_scev_SpecificSInt(Param.LinearStepOrPos),
5924+
m_SpecificLoop(TheLoop))))
59255925
ParamsOk = false;
5926-
break;
5927-
}
5928-
5929-
const SCEVConstant *Step =
5930-
dyn_cast<SCEVConstant>(SAR->getStepRecurrence(*SE));
5931-
5932-
if (!Step ||
5933-
Step->getAPInt().getSExtValue() != Param.LinearStepOrPos)
5934-
ParamsOk = false;
5935-
59365926
break;
59375927
}
59385928
case VFParamKind::GlobalPredicate:

0 commit comments

Comments
 (0)