Skip to content

Commit 434fb0d

Browse files
committed
!fixup fix build failures after rebase, address comments
1 parent 26644e6 commit 434fb0d

File tree

3 files changed

+77
-26
lines changed

3 files changed

+77
-26
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class SCEVUse : public PointerIntPair<const SCEV *, 2> {
8787
void dump() const;
8888
};
8989

90+
/// Provide PointerLikeTypeTraits for SCEVUse, so it can be used with
91+
/// SmallPtrSet, among others.
9092
template <> struct PointerLikeTypeTraits<SCEVUse> {
9193
static inline void *getAsVoidPointer(SCEVUse U) { return U.getOpaqueValue(); }
9294
static inline SCEVUse getFromVoidPointer(void *P) {
@@ -95,13 +97,7 @@ template <> struct PointerLikeTypeTraits<SCEVUse> {
9597
return U;
9698
}
9799

98-
/// Note, we assume here that void* is related to raw malloc'ed memory and
99-
/// that malloc returns objects at least 4-byte aligned. However, this may be
100-
/// wrong, or pointers may be from something other than malloc. In this case,
101-
/// you should specify a real typed pointer or avoid this template.
102-
///
103-
/// All clients should use assertions to do a run-time check to ensure that
104-
/// this is actually true.
100+
/// The Low bits are used by the PointerIntPair.
105101
static constexpr int NumLowBitsAvailable = 0;
106102
};
107103

@@ -978,7 +974,7 @@ class ScalarEvolution {
978974

979975
/// Same as above except this uses the predicated backedge taken info and
980976
/// may require predicates.
981-
const SCEV *
977+
SCEVUse
982978
getPredicatedExitCount(const Loop *L, const BasicBlock *ExitingBlock,
983979
SmallVectorImpl<const SCEVPredicate *> *Predicates,
984980
ExitCountKind Kind = Exact);
@@ -1014,7 +1010,7 @@ class ScalarEvolution {
10141010
/// SCEV predicates to Predicates that are required to be true in order for
10151011
/// the answer to be correct. Predicates can be checked with run-time
10161012
/// checks and can be used to perform loop versioning.
1017-
const SCEV *getPredicatedConstantMaxBackedgeTakenCount(
1013+
SCEVUse getPredicatedConstantMaxBackedgeTakenCount(
10181014
const Loop *L, SmallVectorImpl<const SCEVPredicate *> &Predicates);
10191015

10201016
/// When successful, this returns a SCEV that is greater than or equal
@@ -1029,7 +1025,7 @@ class ScalarEvolution {
10291025
/// SCEV predicates to Predicates that are required to be true in order for
10301026
/// the answer to be correct. Predicates can be checked with run-time
10311027
/// checks and can be used to perform loop versioning.
1032-
const SCEV *getPredicatedSymbolicMaxBackedgeTakenCount(
1028+
SCEVUse getPredicatedSymbolicMaxBackedgeTakenCount(
10331029
const Loop *L, SmallVectorImpl<const SCEVPredicate *> &Predicates);
10341030

10351031
/// Return true if the backedge taken count is either the value returned by
@@ -1466,9 +1462,9 @@ class ScalarEvolution {
14661462

14671463
unsigned computeHash() const {
14681464
return detail::combineHashValue(
1469-
C,
1470-
detail::combineHashValue(reinterpret_cast<uintptr_t>(Op.getPointer()),
1471-
reinterpret_cast<uintptr_t>(Ty)));
1465+
C, detail::combineHashValue(
1466+
reinterpret_cast<uintptr_t>(Op.getRawPointer()),
1467+
reinterpret_cast<uintptr_t>(Ty)));
14721468
}
14731469

14741470
bool operator==(const FoldID &RHS) const {

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static bool hasHugeExpression(ArrayRef<SCEVUse> Ops) {
857857
template <typename FoldT, typename IsIdentityT, typename IsAbsorberT>
858858
static const SCEV *
859859
constantFoldAndGroupOps(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT,
860-
SmallVectorImpl<const SCEV *> &Ops, FoldT Fold,
860+
SmallVectorImpl<SCEVUse> &Ops, FoldT Fold,
861861
IsIdentityT IsIdentity, IsAbsorberT IsAbsorber) {
862862
const SCEVConstant *Folded = nullptr;
863863
for (unsigned Idx = 0; Idx < Ops.size();) {
@@ -2263,12 +2263,12 @@ SCEVUse ScalarEvolution::getAnyExtendExpr(SCEVUse Op, Type *Ty) {
22632263
/// may be exposed. This helps getAddRecExpr short-circuit extra work in
22642264
/// the common case where no interesting opportunities are present, and
22652265
/// is also used as a check to avoid infinite recursion.
2266-
static bool
2267-
CollectAddOperandsWithScales(SmallDenseMap<const SCEV *, APInt, 16> &M,
2268-
SmallVectorImpl<SCEVUse> &NewOps,
2269-
APInt &AccumulatedConstant,
2270-
ArrayRef<SCEVUse> Ops, const APInt &Scale,
2271-
ScalarEvolution &SE) {
2266+
static bool CollectAddOperandsWithScales(SmallDenseMap<SCEVUse, APInt, 16> &M,
2267+
SmallVectorImpl<SCEVUse> &NewOps,
2268+
APInt &AccumulatedConstant,
2269+
ArrayRef<SCEVUse> Ops,
2270+
const APInt &Scale,
2271+
ScalarEvolution &SE) {
22722272
bool Interesting = false;
22732273

22742274
// Iterate over the add operands. They are sorted, with constants first.
@@ -8208,7 +8208,7 @@ ScalarEvolution::getSmallConstantTripCount(const Loop *L,
82088208
unsigned ScalarEvolution::getSmallConstantMaxTripCount(
82098209
const Loop *L, SmallVectorImpl<const SCEVPredicate *> *Predicates) {
82108210

8211-
const auto *MaxExitCount =
8211+
SCEVUse MaxExitCount =
82128212
Predicates ? getPredicatedConstantMaxBackedgeTakenCount(L, *Predicates)
82138213
: getConstantMaxBackedgeTakenCount(L);
82148214
return getConstantTripCount(dyn_cast<SCEVConstant>(MaxExitCount));
@@ -8315,12 +8315,12 @@ SCEVUse ScalarEvolution::getBackedgeTakenCount(const Loop *L,
83158315
llvm_unreachable("Invalid ExitCountKind!");
83168316
}
83178317

8318-
const SCEV *ScalarEvolution::getPredicatedSymbolicMaxBackedgeTakenCount(
8318+
SCEVUse ScalarEvolution::getPredicatedSymbolicMaxBackedgeTakenCount(
83198319
const Loop *L, SmallVectorImpl<const SCEVPredicate *> &Preds) {
83208320
return getPredicatedBackedgeTakenInfo(L).getSymbolicMax(L, this, &Preds);
83218321
}
83228322

8323-
const SCEV *ScalarEvolution::getPredicatedConstantMaxBackedgeTakenCount(
8323+
SCEVUse ScalarEvolution::getPredicatedConstantMaxBackedgeTakenCount(
83248324
const Loop *L, SmallVectorImpl<const SCEVPredicate *> &Preds) {
83258325
return getPredicatedBackedgeTakenInfo(L).getConstantMax(this, &Preds);
83268326
}
@@ -9221,7 +9221,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
92219221
isKnownPositive(AR->getStepRecurrence(*this))) {
92229222
auto Flags = AR->getNoWrapFlags();
92239223
Flags = setFlags(Flags, WrapType);
9224-
SmallVector<const SCEV*> Operands{AR->operands()};
9224+
SmallVector<SCEVUse> Operands{AR->operands()};
92259225
Flags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, Flags);
92269226
setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
92279227
}
@@ -13783,7 +13783,7 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1378313783
}
1378413784
Preds.clear();
1378513785

13786-
auto *PredConstantMax =
13786+
auto PredConstantMax =
1378713787
SE->getPredicatedConstantMaxBackedgeTakenCount(L, Preds);
1378813788
if (PredConstantMax != ConstantBTC) {
1378913789
assert(!Preds.empty() &&
@@ -13803,7 +13803,7 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1380313803
}
1380413804
Preds.clear();
1380513805

13806-
auto *PredSymbolicMax =
13806+
auto PredSymbolicMax =
1380713807
SE->getPredicatedSymbolicMaxBackedgeTakenCount(L, Preds);
1380813808
if (SymbolicBTC != PredSymbolicMax) {
1380913809
assert(!Preds.empty() &&

llvm/unittests/Analysis/ScalarEvolutionTest.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,4 +1707,59 @@ TEST_F(ScalarEvolutionsTest, ComplexityComparatorIsStrictWeakOrdering) {
17071707
});
17081708
}
17091709

1710+
TEST_F(ScalarEvolutionsTest, SCEVUseWithFlags) {
1711+
Type *Ty = IntegerType::get(Context, 32);
1712+
FunctionType *FTy =
1713+
FunctionType::get(Type::getVoidTy(Context), {Ty, Ty, Ty}, false);
1714+
Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
1715+
BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
1716+
ReturnInst::Create(Context, nullptr, BB);
1717+
1718+
Value *V0 = F->getArg(0);
1719+
Value *V1 = F->getArg(1);
1720+
Value *V2 = F->getArg(2);
1721+
1722+
ScalarEvolution SE = buildSE(*F);
1723+
1724+
const SCEV *S0 = SE.getSCEV(V0);
1725+
const SCEV *S1 = SE.getSCEV(V1);
1726+
const SCEV *S2 = SE.getSCEV(V2);
1727+
1728+
SCEVUse AddNoFlags = SE.getAddExpr(S0, SE.getConstant(S0->getType(), 2));
1729+
SCEVUse AddWithFlag2 = {AddNoFlags, 2};
1730+
SCEVUse MulNoFlags = SE.getMulExpr(AddNoFlags, S1);
1731+
SCEVUse MulFlags2 = SE.getMulExpr(AddWithFlag2, S1);
1732+
EXPECT_EQ(AddNoFlags.getCanonical(SE), AddWithFlag2.getCanonical(SE));
1733+
EXPECT_EQ(MulNoFlags.getCanonical(SE), MulFlags2.getCanonical(SE));
1734+
1735+
SCEVUse AddWithFlag1 = {AddNoFlags, 1};
1736+
SCEVUse MulFlags1 = SE.getMulExpr(AddWithFlag1, S1);
1737+
EXPECT_EQ(MulNoFlags.getCanonical(SE), MulFlags1.getCanonical(SE));
1738+
EXPECT_EQ(MulFlags1.getCanonical(SE), MulFlags2.getCanonical(SE));
1739+
1740+
SCEVUse AddNoFlags2 = SE.getAddExpr(S0, SE.getConstant(S0->getType(), 2));
1741+
EXPECT_EQ(AddNoFlags.getCanonical(SE), AddNoFlags2.getCanonical(SE));
1742+
EXPECT_EQ(AddNoFlags2.getCanonical(SE), AddWithFlag2.getCanonical(SE));
1743+
1744+
SCEVUse MulFlags22 = SE.getMulExpr(AddWithFlag2, S1);
1745+
EXPECT_EQ(MulFlags22.getCanonical(SE), MulFlags2.getCanonical(SE));
1746+
EXPECT_EQ(MulNoFlags.getCanonical(SE), MulFlags22.getCanonical(SE));
1747+
1748+
SCEVUse MulNoFlags2 = SE.getMulExpr(AddNoFlags, S1);
1749+
EXPECT_EQ(MulNoFlags.getCanonical(SE), MulNoFlags2.getCanonical(SE));
1750+
EXPECT_EQ(MulNoFlags2.getCanonical(SE), MulFlags2.getCanonical(SE));
1751+
EXPECT_EQ(MulNoFlags2.getCanonical(SE), MulFlags22.getCanonical(SE));
1752+
1753+
SE.getAddExpr(MulNoFlags, S2);
1754+
SE.getAddExpr(MulFlags1, S2);
1755+
SE.getAddExpr(MulFlags2, S2);
1756+
SCEVUse AddMulNoFlags = SE.getAddExpr(MulNoFlags, S2);
1757+
SCEVUse AddMulFlags1 = SE.getAddExpr(MulFlags1, S2);
1758+
SCEVUse AddMulFlags2 = SE.getAddExpr(MulFlags2, S2);
1759+
1760+
EXPECT_EQ(AddMulNoFlags.getCanonical(SE), AddMulFlags1.getCanonical(SE));
1761+
EXPECT_EQ(AddMulNoFlags.getCanonical(SE), AddMulFlags2.getCanonical(SE));
1762+
EXPECT_EQ(AddMulFlags1.getCanonical(SE), AddMulFlags2.getCanonical(SE));
1763+
}
1764+
17101765
} // end namespace llvm

0 commit comments

Comments
 (0)