Skip to content

Commit 37af84e

Browse files
committed
[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 (cherry picked from commit a321ce3)
1 parent 1da20e6 commit 37af84e

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
@@ -636,8 +636,12 @@ class ScalarEvolution {
636636
/// \p GEP The GEP. The indices contained in the GEP itself are ignored,
637637
/// instead we use IndexExprs.
638638
/// \p IndexExprs The expressions for the indices.
639-
LLVM_ABI const SCEV *
640-
getGEPExpr(GEPOperator *GEP, const SmallVectorImpl<const SCEV *> &IndexExprs);
639+
LLVM_ABI const SCEV *getGEPExpr(GEPOperator *GEP,
640+
ArrayRef<const SCEV *> IndexExprs);
641+
LLVM_ABI const SCEV *getGEPExpr(const SCEV *BaseExpr,
642+
ArrayRef<const SCEV *> IndexExprs,
643+
Type *SrcElementTy,
644+
GEPNoWrapFlags NW = GEPNoWrapFlags::none());
641645
LLVM_ABI const SCEV *getAbsExpr(const SCEV *Op, bool IsNSW);
642646
LLVM_ABI const SCEV *getMinMaxExpr(SCEVTypes Kind,
643647
SmallVectorImpl<const SCEV *> &Operands);

llvm/lib/Analysis/ScalarEvolution.cpp

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

3781-
const SCEV *
3782-
ScalarEvolution::getGEPExpr(GEPOperator *GEP,
3783-
const SmallVectorImpl<const SCEV *> &IndexExprs) {
3781+
const SCEV *ScalarEvolution::getGEPExpr(GEPOperator *GEP,
3782+
ArrayRef<const SCEV *> IndexExprs) {
37843783
const SCEV *BaseExpr = getSCEV(GEP->getPointerOperand());
37853784
// getSCEV(Base)->getType() has the same address space as Base->getType()
37863785
// because SCEV::getType() preserves the address space.
3787-
Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
37883786
GEPNoWrapFlags NW = GEP->getNoWrapFlags();
37893787
if (NW != GEPNoWrapFlags::none()) {
37903788
// We'd like to propagate flags from the IR to the corresponding SCEV nodes,
@@ -3797,13 +3795,20 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
37973795
NW = GEPNoWrapFlags::none();
37983796
}
37993797

3798+
return getGEPExpr(BaseExpr, IndexExprs, GEP->getSourceElementType(), NW);
3799+
}
3800+
3801+
const SCEV *ScalarEvolution::getGEPExpr(const SCEV *BaseExpr,
3802+
ArrayRef<const SCEV *> IndexExprs,
3803+
Type *SrcElementTy, GEPNoWrapFlags NW) {
38003804
SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap;
38013805
if (NW.hasNoUnsignedSignedWrap())
38023806
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNSW);
38033807
if (NW.hasNoUnsignedWrap())
38043808
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNUW);
38053809

3806-
Type *CurTy = GEP->getType();
3810+
Type *CurTy = BaseExpr->getType();
3811+
Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
38073812
bool FirstIter = true;
38083813
SmallVector<const SCEV *, 4> Offsets;
38093814
for (const SCEV *IndexExpr : IndexExprs) {
@@ -3822,7 +3827,7 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
38223827
if (FirstIter) {
38233828
assert(isa<PointerType>(CurTy) &&
38243829
"The first index of a GEP indexes a pointer");
3825-
CurTy = GEP->getSourceElementType();
3830+
CurTy = SrcElementTy;
38263831
FirstIter = false;
38273832
} else {
38283833
CurTy = GetElementPtrInst::getTypeAtIndex(CurTy, (uint64_t)0);

0 commit comments

Comments
 (0)