From 8dff03911c5efa7a3abd6fb43f09233758075b20 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Sun, 13 Nov 2016 06:59:50 +0000 Subject: [PATCH] Analysis: Simplify the ScalarEvolution::getGEPExpr() interface. NFCI. All existing callers were manually extracting information out of an existing GEP instruction and passing it to getGEPExpr(). Simplify the interface by changing it to take a GEPOperator instead. llvm-svn: 286751 --- llvm/include/llvm/Analysis/ScalarEvolution.h | 10 ++++------ llvm/lib/Analysis/ScalarEvolution.cpp | 15 +++++++-------- llvm/lib/Transforms/Scalar/NaryReassociate.cpp | 5 ++--- llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp | 4 +--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index c714199..e0934da 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1188,13 +1188,11 @@ public: } /// Returns an expression for a GEP /// - /// \p PointeeType The type used as the basis for the pointer arithmetics - /// \p BaseExpr The expression for the pointer operand. + /// \p GEP The GEP. The indices contained in the GEP itself are ignored, + /// instead we use IndexExprs. /// \p IndexExprs The expressions for the indices. - /// \p InBounds Whether the GEP is in bounds. - const SCEV *getGEPExpr(Type *PointeeType, const SCEV *BaseExpr, - const SmallVectorImpl &IndexExprs, - bool InBounds = false); + const SCEV *getGEPExpr(GEPOperator *GEP, + const SmallVectorImpl &IndexExprs); const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS); const SCEV *getSMaxExpr(SmallVectorImpl &Operands); const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index cb647d0..25e1de4 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -3015,9 +3015,9 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl &Operands, } const SCEV * -ScalarEvolution::getGEPExpr(Type *PointeeType, const SCEV *BaseExpr, - const SmallVectorImpl &IndexExprs, - bool InBounds) { +ScalarEvolution::getGEPExpr(GEPOperator *GEP, + const SmallVectorImpl &IndexExprs) { + const SCEV *BaseExpr = getSCEV(GEP->getPointerOperand()); // getSCEV(Base)->getType() has the same address space as Base->getType() // because SCEV::getType() preserves the address space. Type *IntPtrTy = getEffectiveSCEVType(BaseExpr->getType()); @@ -3026,12 +3026,13 @@ ScalarEvolution::getGEPExpr(Type *PointeeType, const SCEV *BaseExpr, // flow and the no-overflow bits may not be valid for the expression in any // context. This can be fixed similarly to how these flags are handled for // adds. - SCEV::NoWrapFlags Wrap = InBounds ? SCEV::FlagNSW : SCEV::FlagAnyWrap; + SCEV::NoWrapFlags Wrap = GEP->isInBounds() ? SCEV::FlagNSW + : SCEV::FlagAnyWrap; const SCEV *TotalOffset = getZero(IntPtrTy); // The address space is unimportant. The first thing we do on CurTy is getting // its element type. - Type *CurTy = PointerType::getUnqual(PointeeType); + Type *CurTy = PointerType::getUnqual(GEP->getSourceElementType()); for (const SCEV *IndexExpr : IndexExprs) { // Compute the (potentially symbolic) offset in bytes for this index. if (StructType *STy = dyn_cast(CurTy)) { @@ -4373,9 +4374,7 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) { SmallVector IndexExprs; for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index) IndexExprs.push_back(getSCEV(*Index)); - return getGEPExpr(GEP->getSourceElementType(), - getSCEV(GEP->getPointerOperand()), - IndexExprs, GEP->isInBounds()); + return getGEPExpr(GEP, IndexExprs); } uint32_t diff --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp index e2081f7..81744c0 100644 --- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp +++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp @@ -354,9 +354,8 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP, IndexExprs[I] = SE->getZeroExtendExpr(IndexExprs[I], GEP->getOperand(I)->getType()); } - const SCEV *CandidateExpr = SE->getGEPExpr( - GEP->getSourceElementType(), SE->getSCEV(GEP->getPointerOperand()), - IndexExprs, GEP->isInBounds()); + const SCEV *CandidateExpr = SE->getGEPExpr(cast(GEP), + IndexExprs); Value *Candidate = findClosestMatchingDominator(CandidateExpr, GEP); if (Candidate == nullptr) diff --git a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp index b440db3..c4d18f1 100644 --- a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp @@ -499,9 +499,7 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP( // The base of this candidate is GEP's base plus the offsets of all // indices except this current one. - const SCEV *BaseExpr = SE->getGEPExpr(GEP->getSourceElementType(), - SE->getSCEV(GEP->getPointerOperand()), - IndexExprs, GEP->isInBounds()); + const SCEV *BaseExpr = SE->getGEPExpr(cast(GEP), IndexExprs); Value *ArrayIdx = GEP->getOperand(I); uint64_t ElementSize = DL->getTypeAllocSize(*GTI); if (ArrayIdx->getType()->getIntegerBitWidth() <= -- 2.7.4