Skip to content

Commit a321ce3

Browse files
authored
[SCEV] Expose getGEPExpr without needing to pass GEPOperator* (NFC) (llvm#164487)
Add a new getGEPExpr variant which is independent of GEPOperator*. To be used to construct SCEVs for VPlan recipes in llvm#161276. PR: llvm#164487
1 parent ae11c5c commit a321ce3

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,12 @@ class ScalarEvolution {
638638
/// \p GEP The GEP. The indices contained in the GEP itself are ignored,
639639
/// instead we use IndexExprs.
640640
/// \p IndexExprs The expressions for the indices.
641-
LLVM_ABI const SCEV *
642-
getGEPExpr(GEPOperator *GEP, const SmallVectorImpl<const SCEV *> &IndexExprs);
641+
LLVM_ABI const SCEV *getGEPExpr(GEPOperator *GEP,
642+
ArrayRef<const SCEV *> IndexExprs);
643+
LLVM_ABI const SCEV *getGEPExpr(const SCEV *BaseExpr,
644+
ArrayRef<const SCEV *> IndexExprs,
645+
Type *SrcElementTy,
646+
GEPNoWrapFlags NW = GEPNoWrapFlags::none());
643647
LLVM_ABI const SCEV *getAbsExpr(const SCEV *Op, bool IsNSW);
644648
LLVM_ABI const SCEV *getMinMaxExpr(SCEVTypes Kind,
645649
SmallVectorImpl<const SCEV *> &Operands);

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,13 +3768,11 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
37683768
return getOrCreateAddRecExpr(Operands, L, Flags);
37693769
}
37703770

3771-
const SCEV *
3772-
ScalarEvolution::getGEPExpr(GEPOperator *GEP,
3773-
const SmallVectorImpl<const SCEV *> &IndexExprs) {
3771+
const SCEV *ScalarEvolution::getGEPExpr(GEPOperator *GEP,
3772+
ArrayRef<const SCEV *> IndexExprs) {
37743773
const SCEV *BaseExpr = getSCEV(GEP->getPointerOperand());
37753774
// getSCEV(Base)->getType() has the same address space as Base->getType()
37763775
// because SCEV::getType() preserves the address space.
3777-
Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
37783776
GEPNoWrapFlags NW = GEP->getNoWrapFlags();
37793777
if (NW != GEPNoWrapFlags::none()) {
37803778
// We'd like to propagate flags from the IR to the corresponding SCEV nodes,
@@ -3787,13 +3785,20 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
37873785
NW = GEPNoWrapFlags::none();
37883786
}
37893787

3788+
return getGEPExpr(BaseExpr, IndexExprs, GEP->getSourceElementType(), NW);
3789+
}
3790+
3791+
const SCEV *ScalarEvolution::getGEPExpr(const SCEV *BaseExpr,
3792+
ArrayRef<const SCEV *> IndexExprs,
3793+
Type *SrcElementTy, GEPNoWrapFlags NW) {
37903794
SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap;
37913795
if (NW.hasNoUnsignedSignedWrap())
37923796
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNSW);
37933797
if (NW.hasNoUnsignedWrap())
37943798
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNUW);
37953799

3796-
Type *CurTy = GEP->getType();
3800+
Type *CurTy = BaseExpr->getType();
3801+
Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
37973802
bool FirstIter = true;
37983803
SmallVector<const SCEV *, 4> Offsets;
37993804
for (const SCEV *IndexExpr : IndexExprs) {
@@ -3812,7 +3817,7 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
38123817
if (FirstIter) {
38133818
assert(isa<PointerType>(CurTy) &&
38143819
"The first index of a GEP indexes a pointer");
3815-
CurTy = GEP->getSourceElementType();
3820+
CurTy = SrcElementTy;
38163821
FirstIter = false;
38173822
} else {
38183823
CurTy = GetElementPtrInst::getTypeAtIndex(CurTy, (uint64_t)0);

0 commit comments

Comments
 (0)