Skip to content

Commit 89822e5

Browse files
committed
!fixup fix build failures after rebase, address comments
1 parent 23ccc88 commit 89822e5

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();) {
@@ -2262,12 +2262,12 @@ SCEVUse ScalarEvolution::getAnyExtendExpr(SCEVUse Op, Type *Ty) {
22622262
/// may be exposed. This helps getAddRecExpr short-circuit extra work in
22632263
/// the common case where no interesting opportunities are present, and
22642264
/// is also used as a check to avoid infinite recursion.
2265-
static bool
2266-
CollectAddOperandsWithScales(SmallDenseMap<const SCEV *, APInt, 16> &M,
2267-
SmallVectorImpl<SCEVUse> &NewOps,
2268-
APInt &AccumulatedConstant,
2269-
ArrayRef<SCEVUse> Ops, const APInt &Scale,
2270-
ScalarEvolution &SE) {
2265+
static bool CollectAddOperandsWithScales(SmallDenseMap<SCEVUse, APInt, 16> &M,
2266+
SmallVectorImpl<SCEVUse> &NewOps,
2267+
APInt &AccumulatedConstant,
2268+
ArrayRef<SCEVUse> Ops,
2269+
const APInt &Scale,
2270+
ScalarEvolution &SE) {
22712271
bool Interesting = false;
22722272

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

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

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

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

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

13805-
auto *PredSymbolicMax =
13805+
auto PredSymbolicMax =
1380613806
SE->getPredicatedSymbolicMaxBackedgeTakenCount(L, Preds);
1380713807
if (SymbolicBTC != PredSymbolicMax) {
1380813808
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)