|
38 | 38 | #include "llvm/Analysis/MemorySSAUpdater.h" |
39 | 39 | #include "llvm/Analysis/ScalarEvolution.h" |
40 | 40 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
| 41 | +#include "llvm/Analysis/ScalarEvolutionPatternMatch.h" |
41 | 42 | #include "llvm/Analysis/TargetLibraryInfo.h" |
42 | 43 | #include "llvm/Analysis/TargetTransformInfo.h" |
43 | 44 | #include "llvm/Analysis/ValueTracking.h" |
|
53 | 54 | #include "llvm/IR/InstrTypes.h" |
54 | 55 | #include "llvm/IR/Instruction.h" |
55 | 56 | #include "llvm/IR/Instructions.h" |
56 | | -#include "llvm/IR/IntrinsicInst.h" |
57 | 57 | #include "llvm/IR/Intrinsics.h" |
58 | 58 | #include "llvm/IR/PassManager.h" |
59 | 59 | #include "llvm/IR/PatternMatch.h" |
|
79 | 79 |
|
80 | 80 | using namespace llvm; |
81 | 81 | using namespace PatternMatch; |
| 82 | +using namespace SCEVPatternMatch; |
82 | 83 |
|
83 | 84 | #define DEBUG_TYPE "indvars" |
84 | 85 |
|
@@ -806,12 +807,9 @@ static bool isLoopCounter(PHINode* Phi, Loop *L, |
806 | 807 | if (!SE->isSCEVable(Phi->getType())) |
807 | 808 | return false; |
808 | 809 |
|
809 | | - const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(Phi)); |
810 | | - if (!AR || AR->getLoop() != L || !AR->isAffine()) |
811 | | - return false; |
812 | | - |
813 | | - const SCEV *Step = dyn_cast<SCEVConstant>(AR->getStepRecurrence(*SE)); |
814 | | - if (!Step || !Step->isOne()) |
| 810 | + const SCEV *S = SE->getSCEV(Phi); |
| 811 | + if (!match(S, m_scev_AffineAddRec(m_SCEV(), m_scev_One())) || |
| 812 | + cast<SCEVAddRecExpr>(S)->getLoop() != L) |
815 | 813 | return false; |
816 | 814 |
|
817 | 815 | int LatchIdx = Phi->getBasicBlockIndex(L->getLoopLatch()); |
|
0 commit comments