Skip to content

Commit 790ea77

Browse files
committed
!fixup pass GEPNoWrapFlags
1 parent 4774756 commit 790ea77

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +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);
643-
LLVM_ABI const SCEV *getGEPExpr(
644-
const SCEV *BaseExpr, const SmallVectorImpl<const SCEV *> &IndexExprs,
645-
Type *SrcElementTy, SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap);
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());
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: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3768,9 +3768,8 @@ 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.
@@ -3786,20 +3785,18 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
37863785
NW = GEPNoWrapFlags::none();
37873786
}
37883787

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) {
37893794
SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap;
37903795
if (NW.hasNoUnsignedSignedWrap())
37913796
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNSW);
37923797
if (NW.hasNoUnsignedWrap())
37933798
OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNUW);
37943799

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) {
38033800
Type *CurTy = BaseExpr->getType();
38043801
Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType());
38053802
bool FirstIter = true;
@@ -3845,9 +3842,8 @@ ScalarEvolution::getGEPExpr(const SCEV *BaseExpr,
38453842
// Add the base address and the offset. We cannot use the nsw flag, as the
38463843
// base address is unsigned. However, if we know that the offset is
38473844
// non-negative, we can use nuw.
3848-
bool NUW =
3849-
hasFlags(OffsetWrap, SCEV::FlagNUW) ||
3850-
(hasFlags(OffsetWrap, SCEV::FlagNSW) && isKnownNonNegative(Offset));
3845+
bool NUW = NW.hasNoUnsignedWrap() ||
3846+
(NW.hasNoUnsignedSignedWrap() && isKnownNonNegative(Offset));
38513847
SCEV::NoWrapFlags BaseWrap = NUW ? SCEV::FlagNUW : SCEV::FlagAnyWrap;
38523848
auto *GEPExpr = getAddExpr(BaseExpr, Offset, BaseWrap);
38533849
assert(BaseExpr->getType() == GEPExpr->getType() &&

0 commit comments

Comments
 (0)