79
79
#include "llvm/Analysis/LoopInfo.h"
80
80
#include "llvm/Analysis/MemoryBuiltins.h"
81
81
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
82
+ #include "llvm/Analysis/ScalarEvolutionPatternMatch.h"
82
83
#include "llvm/Analysis/TargetLibraryInfo.h"
83
84
#include "llvm/Analysis/ValueTracking.h"
84
85
#include "llvm/Config/llvm-config.h"
133
134
134
135
using namespace llvm;
135
136
using namespace PatternMatch;
137
+ using namespace SCEVPatternMatch;
136
138
137
139
#define DEBUG_TYPE "scalar-evolution"
138
140
@@ -3423,9 +3425,8 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
3423
3425
return S;
3424
3426
3425
3427
// 0 udiv Y == 0
3426
- if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS))
3427
- if (LHSC->getValue()->isZero())
3428
- return LHS;
3428
+ if (match(LHS, m_scev_Zero()))
3429
+ return LHS;
3429
3430
3430
3431
if (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS)) {
3431
3432
if (RHSC->getValue()->isOne())
@@ -10593,7 +10594,6 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
10593
10594
// Get the initial value for the loop.
10594
10595
const SCEV *Start = getSCEVAtScope(AddRec->getStart(), L->getParentLoop());
10595
10596
const SCEV *Step = getSCEVAtScope(AddRec->getOperand(1), L->getParentLoop());
10596
- const SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step);
10597
10597
10598
10598
if (!isLoopInvariant(Step, L))
10599
10599
return getCouldNotCompute();
@@ -10615,8 +10615,8 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
10615
10615
// Handle unitary steps, which cannot wraparound.
10616
10616
// 1*N = -Start; -1*N = Start (mod 2^BW), so:
10617
10617
// N = Distance (as unsigned)
10618
- if (StepC &&
10619
- (StepC->getValue()->isOne() || StepC->getValue()->isMinusOne( ))) {
10618
+
10619
+ if (match(Step, m_CombineOr(m_scev_One(), m_scev_MinusOne() ))) {
10620
10620
APInt MaxBECount = getUnsignedRangeMax(applyLoopGuards(Distance, Guards));
10621
10621
MaxBECount = APIntOps::umin(MaxBECount, getUnsignedRangeMax(Distance));
10622
10622
@@ -10668,6 +10668,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
10668
10668
}
10669
10669
10670
10670
// Solve the general equation.
10671
+ const SCEVConstant *StepC = dyn_cast<SCEVConstant>(Step);
10671
10672
if (!StepC || StepC->getValue()->isZero())
10672
10673
return getCouldNotCompute();
10673
10674
const SCEV *E = SolveLinEquationWithOverflow(
0 commit comments