@@ -3774,7 +3774,6 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
37743774 const SCEV *BaseExpr = getSCEV(GEP->getPointerOperand());
37753775 // getSCEV(Base)->getType() has the same address space as Base->getType()
37763776 // because SCEV::getType() preserves the address space.
3777- Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
37783777 GEPNoWrapFlags NW = GEP->getNoWrapFlags();
37793778 if (NW != GEPNoWrapFlags::none()) {
37803779 // We'd like to propagate flags from the IR to the corresponding SCEV nodes,
@@ -3793,7 +3792,16 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
37933792 if (NW.hasNoUnsignedWrap())
37943793 OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNUW);
37953794
3796- Type *CurTy = GEP->getType();
3795+ return getGEPExpr(BaseExpr, IndexExprs, GEP->getSourceElementType(),
3796+ OffsetWrap);
3797+ }
3798+
3799+ const SCEV *
3800+ ScalarEvolution::getGEPExpr(const SCEV *BaseExpr,
3801+ const SmallVectorImpl<const SCEV *> &IndexExprs,
3802+ Type *SrcElementTy, SCEV::NoWrapFlags OffsetWrap) {
3803+ Type *CurTy = BaseExpr->getType();
3804+ Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
37973805 bool FirstIter = true;
37983806 SmallVector<const SCEV *, 4> Offsets;
37993807 for (const SCEV *IndexExpr : IndexExprs) {
@@ -3812,7 +3820,7 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
38123820 if (FirstIter) {
38133821 assert(isa<PointerType>(CurTy) &&
38143822 "The first index of a GEP indexes a pointer");
3815- CurTy = GEP->getSourceElementType() ;
3823+ CurTy = SrcElementTy ;
38163824 FirstIter = false;
38173825 } else {
38183826 CurTy = GetElementPtrInst::getTypeAtIndex(CurTy, (uint64_t)0);
@@ -3837,8 +3845,9 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
38373845 // Add the base address and the offset. We cannot use the nsw flag, as the
38383846 // base address is unsigned. However, if we know that the offset is
38393847 // non-negative, we can use nuw.
3840- bool NUW = NW.hasNoUnsignedWrap() ||
3841- (NW.hasNoUnsignedSignedWrap() && isKnownNonNegative(Offset));
3848+ bool NUW =
3849+ hasFlags(OffsetWrap, SCEV::FlagNUW) ||
3850+ (hasFlags(OffsetWrap, SCEV::FlagNSW) && isKnownNonNegative(Offset));
38423851 SCEV::NoWrapFlags BaseWrap = NUW ? SCEV::FlagNUW : SCEV::FlagAnyWrap;
38433852 auto *GEPExpr = getAddExpr(BaseExpr, Offset, BaseWrap);
38443853 assert(BaseExpr->getType() == GEPExpr->getType() &&
0 commit comments