Skip to content

Commit c362fe9

Browse files
committed
!fixup use raw pointer (const SCEV * + lower bits) for AddPointer.
1 parent d660a7c commit c362fe9

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class SCEVUse : public PointerIntPair<const SCEV *, 2> {
8181
const SCEV *operator->() const { return getPointer(); }
8282
const SCEV *operator->() { return getPointer(); }
8383

84+
void *getRawPointer() { return getOpaqueValue(); }
85+
8486
/// Print out the internal representation of this scalar to the specified
8587
/// stream. This should really only be used for debugging purposes.
8688
void print(raw_ostream &OS) const;

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ SCEVUse ScalarEvolution::getLosslessPtrToIntExpr(SCEVUse Op, unsigned Depth) {
10231023
// What would be an ID for such a SCEV cast expression?
10241024
FoldingSetNodeID ID;
10251025
ID.AddInteger(scPtrToInt);
1026-
ID.AddPointer(Op);
1026+
ID.AddPointer(Op.getRawPointer());
10271027

10281028
void *IP = nullptr;
10291029

@@ -1154,7 +1154,7 @@ SCEVUse ScalarEvolution::getTruncateExpr(SCEVUse Op, Type *Ty, unsigned Depth) {
11541154

11551155
FoldingSetNodeID ID;
11561156
ID.AddInteger(scTruncate);
1157-
ID.AddPointer(Op);
1157+
ID.AddPointer(Op.getRawPointer());
11581158
ID.AddPointer(Ty);
11591159
void *IP = nullptr;
11601160
if (SCEVUse S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
@@ -1475,8 +1475,8 @@ bool ScalarEvolution::proveNoWrapByVaryingStart(SCEVUse Start, SCEVUse Step,
14751475

14761476
FoldingSetNodeID ID;
14771477
ID.AddInteger(scAddRecExpr);
1478-
ID.AddPointer(PreStart);
1479-
ID.AddPointer(Step);
1478+
ID.AddPointer(PreStart.getRawPointer());
1479+
ID.AddPointer(Step.getRawPointer());
14801480
ID.AddPointer(L);
14811481
void *IP = nullptr;
14821482
const auto *PreAR =
@@ -1595,7 +1595,7 @@ SCEVUse ScalarEvolution::getZeroExtendExprImpl(SCEVUse Op, Type *Ty,
15951595
// computed a SCEV for this Op and Ty.
15961596
FoldingSetNodeID ID;
15971597
ID.AddInteger(scZeroExtend);
1598-
ID.AddPointer(Op);
1598+
ID.AddPointer(Op.getRawPointer());
15991599
ID.AddPointer(Ty);
16001600
void *IP = nullptr;
16011601
if (SCEVUse S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
@@ -1936,7 +1936,7 @@ SCEVUse ScalarEvolution::getSignExtendExprImpl(SCEVUse Op, Type *Ty,
19361936
// computed a SCEV for this Op and Ty.
19371937
FoldingSetNodeID ID;
19381938
ID.AddInteger(scSignExtend);
1939-
ID.AddPointer(Op);
1939+
ID.AddPointer(Op.getRawPointer());
19401940
ID.AddPointer(Ty);
19411941
void *IP = nullptr;
19421942
if (SCEVUse S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
@@ -2242,7 +2242,7 @@ SCEVUse ScalarEvolution::getAnyExtendExpr(SCEVUse Op, Type *Ty) {
22422242
/// may be exposed. This helps getAddRecExpr short-circuit extra work in
22432243
/// the common case where no interesting opportunities are present, and
22442244
/// is also used as a check to avoid infinite recursion.
2245-
static bool CollectAddOperandsWithScales(DenseMap<const SCEV *, APInt> &M,
2245+
static bool CollectAddOperandsWithScales(DenseMap<SCEVUse, APInt> &M,
22462246
SmallVectorImpl<SCEVUse> &NewOps,
22472247
APInt &AccumulatedConstant,
22482248
ArrayRef<SCEVUse> Ops,
@@ -2290,7 +2290,7 @@ static bool CollectAddOperandsWithScales(DenseMap<const SCEV *, APInt> &M,
22902290
}
22912291
} else {
22922292
// An ordinary operand. Update the map.
2293-
std::pair<DenseMap<const SCEV *, APInt>::iterator, bool> Pair =
2293+
std::pair<DenseMap<SCEVUse, APInt>::iterator, bool> Pair =
22942294
M.insert({Ops[i], Scale});
22952295
if (Pair.second) {
22962296
NewOps.push_back(Pair.first->first);
@@ -2762,7 +2762,7 @@ SCEVUse ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVUse> &Ops,
27622762
// operands multiplied by constant values.
27632763
if (Idx < Ops.size() && isa<SCEVMulExpr>(Ops[Idx])) {
27642764
uint64_t BitWidth = getTypeSizeInBits(Ty);
2765-
DenseMap<const SCEV *, APInt> M;
2765+
DenseMap<SCEVUse, APInt> M;
27662766
SmallVector<SCEVUse, 8> NewOps;
27672767
APInt AccumulatedConstant(BitWidth, 0);
27682768
if (CollectAddOperandsWithScales(M, NewOps, AccumulatedConstant,
@@ -2999,7 +2999,7 @@ SCEVUse ScalarEvolution::getOrCreateAddExpr(ArrayRef<SCEVUse> Ops,
29992999
FoldingSetNodeID ID;
30003000
ID.AddInteger(scAddExpr);
30013001
for (SCEVUse Op : Ops)
3002-
ID.AddPointer(Op);
3002+
ID.AddPointer(Op.getRawPointer());
30033003
void *IP = nullptr;
30043004
SCEVAddExpr *S =
30053005
static_cast<SCEVAddExpr *>(UniqueSCEVs.FindNodeOrInsertPos(ID, IP));
@@ -3021,7 +3021,7 @@ SCEVUse ScalarEvolution::getOrCreateAddRecExpr(ArrayRef<SCEVUse> Ops,
30213021
FoldingSetNodeID ID;
30223022
ID.AddInteger(scAddRecExpr);
30233023
for (SCEVUse Op : Ops)
3024-
ID.AddPointer(Op);
3024+
ID.AddPointer(Op.getRawPointer());
30253025
ID.AddPointer(L);
30263026
void *IP = nullptr;
30273027
SCEVAddRecExpr *S =
@@ -3044,7 +3044,7 @@ SCEVUse ScalarEvolution::getOrCreateMulExpr(ArrayRef<SCEVUse> Ops,
30443044
FoldingSetNodeID ID;
30453045
ID.AddInteger(scMulExpr);
30463046
for (SCEVUse Op : Ops)
3047-
ID.AddPointer(Op);
3047+
ID.AddPointer(Op.getRawPointer());
30483048
void *IP = nullptr;
30493049
SCEVMulExpr *S =
30503050
static_cast<SCEVMulExpr *>(UniqueSCEVs.FindNodeOrInsertPos(ID, IP));
@@ -3444,8 +3444,8 @@ SCEVUse ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
34443444

34453445
FoldingSetNodeID ID;
34463446
ID.AddInteger(scUDivExpr);
3447-
ID.AddPointer(LHS);
3448-
ID.AddPointer(RHS);
3447+
ID.AddPointer(LHS.getRawPointer());
3448+
ID.AddPointer(RHS.getRawPointer());
34493449
void *IP = nullptr;
34503450
if (SCEVUse S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
34513451
return S;
@@ -3511,8 +3511,8 @@ SCEVUse ScalarEvolution::getUDivExpr(SCEVUse LHS, SCEVUse RHS) {
35113511
// already cached.
35123512
ID.clear();
35133513
ID.AddInteger(scUDivExpr);
3514-
ID.AddPointer(LHS);
3515-
ID.AddPointer(RHS);
3514+
ID.AddPointer(LHS.getRawPointer());
3515+
ID.AddPointer(RHS.getRawPointer());
35163516
IP = nullptr;
35173517
if (SCEVUse S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP))
35183518
return S;
@@ -3846,7 +3846,7 @@ SCEV *ScalarEvolution::findExistingSCEVInCache(SCEVTypes SCEVType,
38463846
FoldingSetNodeID ID;
38473847
ID.AddInteger(SCEVType);
38483848
for (SCEVUse Op : Ops)
3849-
ID.AddPointer(Op);
3849+
ID.AddPointer(Op.getRawPointer());
38503850
void *IP = nullptr;
38513851
return UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
38523852
}
@@ -3989,7 +3989,7 @@ SCEVUse ScalarEvolution::getMinMaxExpr(SCEVTypes Kind,
39893989
FoldingSetNodeID ID;
39903990
ID.AddInteger(Kind);
39913991
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
3992-
ID.AddPointer(Ops[i]);
3992+
ID.AddPointer(Ops[i].getRawPointer());
39933993
void *IP = nullptr;
39943994
SCEVUse ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
39953995
if (ExistingSCEV)
@@ -4376,7 +4376,7 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,
43764376
FoldingSetNodeID ID;
43774377
ID.AddInteger(Kind);
43784378
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
4379-
ID.AddPointer(Ops[i]);
4379+
ID.AddPointer(Ops[i].getRawPointer());
43804380
void *IP = nullptr;
43814381
SCEVUse ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
43824382
if (ExistingSCEV)
@@ -14509,8 +14509,8 @@ ScalarEvolution::getComparePredicate(const ICmpInst::Predicate Pred,
1450914509
// Unique this node based on the arguments
1451014510
ID.AddInteger(SCEVPredicate::P_Compare);
1451114511
ID.AddInteger(Pred);
14512-
ID.AddPointer(LHS);
14513-
ID.AddPointer(RHS);
14512+
ID.AddPointer(LHS.getRawPointer());
14513+
ID.AddPointer(RHS.getRawPointer());
1451414514
void *IP = nullptr;
1451514515
if (const auto *S = UniquePreds.FindNodeOrInsertPos(ID, IP))
1451614516
return S;
@@ -14526,6 +14526,7 @@ const SCEVPredicate *ScalarEvolution::getWrapPredicate(
1452614526
FoldingSetNodeID ID;
1452714527
// Unique this node based on the arguments
1452814528
ID.AddInteger(SCEVPredicate::P_Wrap);
14529+
// TODO: Use SCEVUse
1452914530
ID.AddPointer(AR);
1453014531
ID.AddInteger(AddedFlags);
1453114532
void *IP = nullptr;
@@ -15033,13 +15034,13 @@ bool ScalarEvolution::matchURem(SCEVUse Expr, SCEVUse &LHS,
1503315034
/// in the map. It skips AddRecExpr because we cannot guarantee that the
1503415035
/// replacement is loop invariant in the loop of the AddRec.
1503515036
class SCEVLoopGuardRewriter : public SCEVRewriteVisitor<SCEVLoopGuardRewriter> {
15036-
const DenseMap<const SCEV *, SCEVUse> &Map;
15037+
const DenseMap<SCEVUse, SCEVUse> &Map;
1503715038

1503815039
SCEV::NoWrapFlags FlagMask = SCEV::FlagAnyWrap;
1503915040

1504015041
public:
1504115042
SCEVLoopGuardRewriter(ScalarEvolution &SE,
15042-
DenseMap<const SCEV *, SCEVUse > &M,
15043+
DenseMap<SCEVUse, SCEVUse > &M,
1504315044
bool PreserveNUW, bool PreserveNSW)
1504415045
: SCEVRewriteVisitor(SE), Map(M) {
1504515046
if (PreserveNUW)
@@ -15138,7 +15139,7 @@ SCEVUse ScalarEvolution::applyLoopGuards(SCEVUse Expr, const Loop *L) {
1513815139
SmallVector<SCEVUse> ExprsToRewrite;
1513915140
auto CollectCondition = [&](ICmpInst::Predicate Predicate, SCEVUse LHS,
1514015141
SCEVUse RHS,
15141-
DenseMap<const SCEV *, SCEVUse> &RewriteMap) {
15142+
DenseMap<SCEVUse, SCEVUse> &RewriteMap) {
1514215143
// WARNING: It is generally unsound to apply any wrap flags to the proposed
1514315144
// replacement SCEV which isn't directly implied by the structure of that
1514415145
// SCEV. In particular, using contextual facts to imply flags is *NOT*
@@ -15508,7 +15509,7 @@ SCEVUse ScalarEvolution::applyLoopGuards(SCEVUse Expr, const Loop *L) {
1550815509
// Conditions are processed in reverse order, so the earliest conditions is
1550915510
// processed first. This ensures the SCEVs with the shortest dependency chains
1551015511
// are constructed first.
15511-
DenseMap<const SCEV *, SCEVUse> RewriteMap;
15512+
DenseMap<SCEVUse, SCEVUse> RewriteMap;
1551215513
for (auto [Term, EnterIfTrue] : reverse(Terms)) {
1551315514
SmallVector<Value *, 8> Worklist;
1551415515
SmallPtrSet<Value *, 8> Visited;

0 commit comments

Comments
 (0)