Skip to content

Commit fcc832e

Browse files
committed
!fixup pass GEPNoWrapFlags
1 parent 4774756 commit fcc832e

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,10 @@ class ScalarEvolution {
640640
/// \p IndexExprs The expressions for the indices.
641641
LLVM_ABI const SCEV *
642642
getGEPExpr(GEPOperator *GEP, const SmallVectorImpl<const SCEV *> &IndexExprs);
643-
LLVM_ABI const SCEV *getGEPExpr(
644-
const SCEV *BaseExpr, const SmallVectorImpl<const SCEV *> &IndexExprs,
645-
Type *SrcElementTy, SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap);
643+
LLVM_ABI const SCEV *getGEPExpr(const SCEV *BaseExpr,
644+
ArrayRef<const SCEV *> IndexExprs,
645+
Type *SrcElementTy,
646+
GEPNoWrapFlags NW = GEPNoWrapFlags::none());
646647
LLVM_ABI const SCEV *getAbsExpr(const SCEV *Op, bool IsNSW);
647648
LLVM_ABI const SCEV *getMinMaxExpr(SCEVTypes Kind,
648649
SmallVectorImpl<const SCEV *> &Operands);

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,20 +3786,18 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
37863786
NW = GEPNoWrapFlags::none();
37873787
}
37883788

3789+
return getGEPExpr(BaseExpr, IndexExprs, GEP->getSourceElementType(), NW);
3790+
}
3791+
3792+
const SCEV *ScalarEvolution::getGEPExpr(const SCEV *BaseExpr,
3793+
ArrayRef<const SCEV *> IndexExprs,
3794+
Type *SrcElementTy, GEPNoWrapFlags NW) {
37893795
SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap;
37903796
if (NW.hasNoUnsignedSignedWrap())
37913797
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNSW);
37923798
if (NW.hasNoUnsignedWrap())
37933799
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNUW);
37943800

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) {
38033801
Type *CurTy = BaseExpr->getType();
38043802
Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
38053803
bool FirstIter = true;
@@ -3845,9 +3843,8 @@ ScalarEvolution::getGEPExpr(const SCEV *BaseExpr,
38453843
// Add the base address and the offset. We cannot use the nsw flag, as the
38463844
// base address is unsigned. However, if we know that the offset is
38473845
// non-negative, we can use nuw.
3848-
bool NUW =
3849-
hasFlags(OffsetWrap, SCEV::FlagNUW) ||
3850-
(hasFlags(OffsetWrap, SCEV::FlagNSW) && isKnownNonNegative(Offset));
3846+
bool NUW = NW.hasNoUnsignedWrap() ||
3847+
(NW.hasNoUnsignedSignedWrap() && isKnownNonNegative(Offset));
38513848
SCEV::NoWrapFlags BaseWrap = NUW ? SCEV::FlagNUW : SCEV::FlagAnyWrap;
38523849
auto *GEPExpr = getAddExpr(BaseExpr, Offset, BaseWrap);
38533850
assert(BaseExpr->getType() == GEPExpr->getType() &&

0 commit comments

Comments
 (0)