From 259ea987f56a2e68379adfbf290a52ef855d0207 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 26 Jul 2018 21:55:03 +0000 Subject: [PATCH] [SCEV] Add an expandAddToGEP overload for a single operand. NFC. Only wanting to pass a single SCEV operand to use as the offset of the GEP is a common operation. Right now this requires creating a temporary stack array at every call site. Add an overload that encapsulates that pattern and simplify the call sites. Suggested-By: sanjoy (in https://reviews.llvm.org/D49832) llvm-svn: 338072 --- .../llvm/Analysis/ScalarEvolutionExpander.h | 1 + llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h index 6476568..58d4268 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -335,6 +335,7 @@ namespace llvm { Value *expandAddToGEP(const SCEV *const *op_begin, const SCEV *const *op_end, PointerType *PTy, Type *Ty, Value *V); + Value *expandAddToGEP(const SCEV *Op, PointerType *PTy, Type *Ty, Value *V); /// Find a previous Value in ExprValueMap for expand. ScalarEvolution::ValueOffsetPair diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 7f76f05..b49a5cd 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -589,6 +589,12 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, return expand(SE.getAddExpr(Ops)); } +Value *SCEVExpander::expandAddToGEP(const SCEV *Op, PointerType *PTy, Type *Ty, + Value *V) { + const SCEV *const Ops[1] = {Op}; + return expandAddToGEP(Ops, Ops + 1, PTy, Ty, V); +} + /// PickMostRelevantLoop - Given two loops pick the one that's most relevant for /// SCEV expansion. If they are nested, this is the most nested. If they are /// neighboring, pick the later. @@ -1036,8 +1042,7 @@ Value *SCEVExpander::expandIVInc(PHINode *PN, Value *StepV, const Loop *L, if (!isa(StepV)) GEPPtrTy = PointerType::get(Type::getInt1Ty(SE.getContext()), GEPPtrTy->getAddressSpace()); - const SCEV *const StepArray[1] = { SE.getSCEV(StepV) }; - IncV = expandAddToGEP(StepArray, StepArray+1, GEPPtrTy, IntTy, PN); + IncV = expandAddToGEP(SE.getSCEV(StepV), GEPPtrTy, IntTy, PN); if (IncV->getType() != PN->getType()) { IncV = Builder.CreateBitCast(IncV, PN->getType()); rememberInstruction(IncV); @@ -1443,12 +1448,9 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) { if (PointerType *PTy = dyn_cast(ExpandTy)) { if (Result->getType()->isIntegerTy()) { Value *Base = expandCodeFor(PostLoopOffset, ExpandTy); - const SCEV *const OffsetArray[1] = {SE.getUnknown(Result)}; - Result = expandAddToGEP(OffsetArray, OffsetArray + 1, PTy, IntTy, Base); + Result = expandAddToGEP(SE.getUnknown(Result), PTy, IntTy, Base); } else { - const SCEV *const OffsetArray[1] = {PostLoopOffset}; - Result = - expandAddToGEP(OffsetArray, OffsetArray + 1, PTy, IntTy, Result); + Result = expandAddToGEP(PostLoopOffset, PTy, IntTy, Result); } } else { Result = InsertNoopCastOfTo(Result, IntTy); @@ -1500,9 +1502,9 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { // Turn things like ptrtoint+arithmetic+inttoptr into GEP. See the // comments on expandAddToGEP for details. const SCEV *Base = S->getStart(); - const SCEV *RestArray[1] = { Rest }; // Dig into the expression to find the pointer base for a GEP. - ExposePointerBase(Base, RestArray[0], SE); + const SCEV *ExposedRest = Rest; + ExposePointerBase(Base, ExposedRest, SE); // If we found a pointer, expand the AddRec with a GEP. if (PointerType *PTy = dyn_cast(Base->getType())) { // Make sure the Base isn't something exotic, such as a multiplied @@ -1511,7 +1513,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { if (!isa(Base) && !isa(Base)) { Value *StartV = expand(Base); assert(StartV->getType() == PTy && "Pointer type mismatch for GEP!"); - return expandAddToGEP(RestArray, RestArray+1, PTy, Ty, StartV); + return expandAddToGEP(ExposedRest, PTy, Ty, StartV); } } -- 2.7.4