Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ inline bind_ty<const SCEVAddExpr> m_scev_Add(const SCEVAddExpr *&V) {
return V;
}

inline bind_ty<const SCEVMulExpr> m_scev_Mul(const SCEVMulExpr *&V) {
return V;
}

/// Match a specified const SCEV *.
struct specificscev_ty {
const SCEV *Expr;
Expand Down Expand Up @@ -284,14 +288,10 @@ template <typename Op0_t, typename Op1_t> struct SCEVURem_match {
<< SE.getTypeSizeInBits(TruncTy));
return Op0.match(LHS) && Op1.match(RHS);
}
const auto *Add = dyn_cast<SCEVAddExpr>(Expr);
if (Add == nullptr || Add->getNumOperands() != 2)
return false;

const SCEV *A = Add->getOperand(1);
const auto *Mul = dyn_cast<SCEVMulExpr>(Add->getOperand(0));

if (Mul == nullptr)
const SCEV *A;
const SCEVMulExpr *Mul;
if (!SCEVPatternMatch::match(Expr, m_scev_Add(m_scev_Mul(Mul), m_SCEV(A))))
return false;

const auto MatchURemWithDivisor = [&](const SCEV *B) {
Expand Down
27 changes: 10 additions & 17 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4623,17 +4623,11 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V,

/// If Expr computes ~A, return A else return nullptr
static const SCEV *MatchNotExpr(const SCEV *Expr) {
const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Expr);
if (!Add || Add->getNumOperands() != 2 ||
!Add->getOperand(0)->isAllOnesValue())
return nullptr;

const SCEVMulExpr *AddRHS = dyn_cast<SCEVMulExpr>(Add->getOperand(1));
if (!AddRHS || AddRHS->getNumOperands() != 2 ||
!AddRHS->getOperand(0)->isAllOnesValue())
return nullptr;

return AddRHS->getOperand(1);
const SCEV *MulOp;
if (match(Expr, m_scev_Add(m_scev_AllOnes(),
m_scev_Mul(m_scev_AllOnes(), m_SCEV(MulOp)))))
return MulOp;
return nullptr;
}

/// Return a SCEV corresponding to ~V = -1-V
Expand Down Expand Up @@ -12220,12 +12214,11 @@ ScalarEvolution::computeConstantDifference(const SCEV *More, const SCEV *Less) {
// Try to match a common constant multiply.
auto MatchConstMul =
[](const SCEV *S) -> std::optional<std::pair<const SCEV *, APInt>> {
auto *M = dyn_cast<SCEVMulExpr>(S);
if (!M || M->getNumOperands() != 2 ||
!isa<SCEVConstant>(M->getOperand(0)))
return std::nullopt;
return {
{M->getOperand(1), cast<SCEVConstant>(M->getOperand(0))->getAPInt()}};
const APInt *C;
const SCEV *Op;
if (match(S, m_scev_Mul(m_scev_APInt(C), m_SCEV(Op))))
return {{Op, *C}};
return std::nullopt;
};
if (auto MatchedMore = MatchConstMul(More)) {
if (auto MatchedLess = MatchConstMul(Less)) {
Expand Down
Loading