@@ -1381,7 +1381,7 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR, Type *Ty,
1381
1381
// If we know `AR` == {`PreStart`+`Step`,+,`Step`} is `WrapType` (FlagNSW
1382
1382
// or FlagNUW) and that `PreStart` + `Step` is `WrapType` too, then
1383
1383
// `PreAR` == {`PreStart`,+,`Step`} is also `WrapType`. Cache this fact.
1384
- const_cast<SCEVAddRecExpr *>(PreAR)->setNoWrapFlags( WrapType);
1384
+ SE->setNoWrapFlags( const_cast<SCEVAddRecExpr *>(PreAR), WrapType);
1385
1385
}
1386
1386
return PreStart;
1387
1387
}
@@ -1585,7 +1585,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1585
1585
1586
1586
if (!AR->hasNoUnsignedWrap()) {
1587
1587
auto NewFlags = proveNoWrapViaConstantRanges(AR);
1588
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( NewFlags);
1588
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), NewFlags);
1589
1589
}
1590
1590
1591
1591
// If we have special knowledge that this addrec won't overflow,
@@ -1634,7 +1634,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1634
1634
SCEV::FlagAnyWrap, Depth + 1);
1635
1635
if (ZAdd == OperandExtendedAdd) {
1636
1636
// Cache knowledge of AR NUW, which is propagated to this AddRec.
1637
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNUW);
1637
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
1638
1638
// Return the expression with the addrec on the outside.
1639
1639
return getAddRecExpr(
1640
1640
getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this,
@@ -1653,7 +1653,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1653
1653
if (ZAdd == OperandExtendedAdd) {
1654
1654
// Cache knowledge of AR NW, which is propagated to this AddRec.
1655
1655
// Negative step causes unsigned wrap, but it still can't self-wrap.
1656
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNW);
1656
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
1657
1657
// Return the expression with the addrec on the outside.
1658
1658
return getAddRecExpr(
1659
1659
getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this,
@@ -1685,7 +1685,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1685
1685
isKnownOnEveryIteration(ICmpInst::ICMP_ULT, AR, N)) {
1686
1686
// Cache knowledge of AR NUW, which is propagated to this
1687
1687
// AddRec.
1688
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNUW);
1688
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
1689
1689
// Return the expression with the addrec on the outside.
1690
1690
return getAddRecExpr(
1691
1691
getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this,
@@ -1701,7 +1701,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1701
1701
// Cache knowledge of AR NW, which is propagated to this
1702
1702
// AddRec. Negative step causes unsigned wrap, but it
1703
1703
// still can't self-wrap.
1704
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNW);
1704
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
1705
1705
// Return the expression with the addrec on the outside.
1706
1706
return getAddRecExpr(
1707
1707
getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this,
@@ -1730,7 +1730,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1730
1730
}
1731
1731
1732
1732
if (proveNoWrapByVaryingStart<SCEVZeroExtendExpr>(Start, Step, L)) {
1733
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNUW);
1733
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNUW);
1734
1734
return getAddRecExpr(
1735
1735
getExtendAddRecStart<SCEVZeroExtendExpr>(AR, Ty, this, Depth + 1),
1736
1736
getZeroExtendExpr(Step, Ty, Depth + 1), L, AR->getNoWrapFlags());
@@ -1929,7 +1929,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1929
1929
1930
1930
if (!AR->hasNoSignedWrap()) {
1931
1931
auto NewFlags = proveNoWrapViaConstantRanges(AR);
1932
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( NewFlags);
1932
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), NewFlags);
1933
1933
}
1934
1934
1935
1935
// If we have special knowledge that this addrec won't overflow,
@@ -1978,7 +1978,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1978
1978
SCEV::FlagAnyWrap, Depth + 1);
1979
1979
if (SAdd == OperandExtendedAdd) {
1980
1980
// Cache knowledge of AR NSW, which is propagated to this AddRec.
1981
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNSW);
1981
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
1982
1982
// Return the expression with the addrec on the outside.
1983
1983
return getAddRecExpr(
1984
1984
getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this,
@@ -2003,7 +2003,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
2003
2003
// Thus (AR is not NW => SAdd != OperandExtendedAdd) <=>
2004
2004
// (SAdd == OperandExtendedAdd => AR is NW)
2005
2005
2006
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNW);
2006
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNW);
2007
2007
2008
2008
// Return the expression with the addrec on the outside.
2009
2009
return getAddRecExpr(
@@ -2037,7 +2037,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
2037
2037
(isLoopBackedgeGuardedByCond(L, Pred, AR, OverflowLimit) ||
2038
2038
isKnownOnEveryIteration(Pred, AR, OverflowLimit))) {
2039
2039
// Cache knowledge of AR NSW, then propagate NSW to the wide AddRec.
2040
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNSW);
2040
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
2041
2041
return getAddRecExpr(
2042
2042
getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1),
2043
2043
getSignExtendExpr(Step, Ty, Depth + 1), L, AR->getNoWrapFlags());
@@ -2062,7 +2062,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
2062
2062
}
2063
2063
2064
2064
if (proveNoWrapByVaryingStart<SCEVSignExtendExpr>(Start, Step, L)) {
2065
- const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags( SCEV::FlagNSW);
2065
+ setNoWrapFlags( const_cast<SCEVAddRecExpr *>(AR), SCEV::FlagNSW);
2066
2066
return getAddRecExpr(
2067
2067
getExtendAddRecStart<SCEVSignExtendExpr>(AR, Ty, this, Depth + 1),
2068
2068
getSignExtendExpr(Step, Ty, Depth + 1), L, AR->getNoWrapFlags());
@@ -2732,7 +2732,7 @@ ScalarEvolution::getOrCreateAddRecExpr(ArrayRef<const SCEV *> Ops,
2732
2732
UniqueSCEVs.InsertNode(S, IP);
2733
2733
addToLoopUseLists(S);
2734
2734
}
2735
- S-> setNoWrapFlags(Flags);
2735
+ setNoWrapFlags(S, Flags);
2736
2736
return S;
2737
2737
}
2738
2738
@@ -5514,6 +5514,15 @@ static Optional<ConstantRange> GetRangeFromMetadata(Value *V) {
5514
5514
return None;
5515
5515
}
5516
5516
5517
+ void ScalarEvolution::setNoWrapFlags(SCEVAddRecExpr *AddRec,
5518
+ SCEV::NoWrapFlags Flags) {
5519
+ if (AddRec->getNoWrapFlags(Flags) != Flags) {
5520
+ AddRec->setNoWrapFlags(Flags);
5521
+ UnsignedRanges.erase(AddRec);
5522
+ SignedRanges.erase(AddRec);
5523
+ }
5524
+ }
5525
+
5517
5526
/// Determine the range for a particular SCEV. If SignHint is
5518
5527
/// HINT_RANGE_UNSIGNED (resp. HINT_RANGE_SIGNED) then getRange prefers ranges
5519
5528
/// with a "cleaner" unsigned (resp. signed) representation.
0 commit comments