Skip to content

Commit f07fc38

Browse files
authored
[IndVars] Improve code; use SCEVPatternMatch (NFC) (#139533)
1 parent 827027b commit f07fc38

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/Analysis/MemorySSAUpdater.h"
3939
#include "llvm/Analysis/ScalarEvolution.h"
4040
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
41+
#include "llvm/Analysis/ScalarEvolutionPatternMatch.h"
4142
#include "llvm/Analysis/TargetLibraryInfo.h"
4243
#include "llvm/Analysis/TargetTransformInfo.h"
4344
#include "llvm/Analysis/ValueTracking.h"
@@ -53,7 +54,6 @@
5354
#include "llvm/IR/InstrTypes.h"
5455
#include "llvm/IR/Instruction.h"
5556
#include "llvm/IR/Instructions.h"
56-
#include "llvm/IR/IntrinsicInst.h"
5757
#include "llvm/IR/Intrinsics.h"
5858
#include "llvm/IR/PassManager.h"
5959
#include "llvm/IR/PatternMatch.h"
@@ -79,6 +79,7 @@
7979

8080
using namespace llvm;
8181
using namespace PatternMatch;
82+
using namespace SCEVPatternMatch;
8283

8384
#define DEBUG_TYPE "indvars"
8485

@@ -806,12 +807,9 @@ static bool isLoopCounter(PHINode* Phi, Loop *L,
806807
if (!SE->isSCEVable(Phi->getType()))
807808
return false;
808809

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)
815813
return false;
816814

817815
int LatchIdx = Phi->getBasicBlockIndex(L->getLoopLatch());

0 commit comments

Comments
 (0)