Skip to content

Commit 3a3232d

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

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;
@@ -3843,7 +3843,7 @@ SCEV *ScalarEvolution::findExistingSCEVInCache(SCEVTypes SCEVType,
38433843
FoldingSetNodeID ID;
38443844
ID.AddInteger(SCEVType);
38453845
for (SCEVUse Op : Ops)
3846-
ID.AddPointer(Op);
3846+
ID.AddPointer(Op.getRawPointer());
38473847
void *IP = nullptr;
38483848
return UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
38493849
}
@@ -3986,7 +3986,7 @@ SCEVUse ScalarEvolution::getMinMaxExpr(SCEVTypes Kind,
39863986
FoldingSetNodeID ID;
39873987
ID.AddInteger(Kind);
39883988
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
3989-
ID.AddPointer(Ops[i]);
3989+
ID.AddPointer(Ops[i].getRawPointer());
39903990
void *IP = nullptr;
39913991
SCEVUse ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
39923992
if (ExistingSCEV)
@@ -4373,7 +4373,7 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind,
43734373
FoldingSetNodeID ID;
43744374
ID.AddInteger(Kind);
43754375
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
4376-
ID.AddPointer(Ops[i]);
4376+
ID.AddPointer(Ops[i].getRawPointer());
43774377
void *IP = nullptr;
43784378
SCEVUse ExistingSCEV = UniqueSCEVs.FindNodeOrInsertPos(ID, IP);
43794379
if (ExistingSCEV)
@@ -14430,8 +14430,8 @@ ScalarEvolution::getComparePredicate(const ICmpInst::Predicate Pred,
1443014430
// Unique this node based on the arguments
1443114431
ID.AddInteger(SCEVPredicate::P_Compare);
1443214432
ID.AddInteger(Pred);
14433-
ID.AddPointer(LHS);
14434-
ID.AddPointer(RHS);
14433+
ID.AddPointer(LHS.getRawPointer());
14434+
ID.AddPointer(RHS.getRawPointer());
1443514435
void *IP = nullptr;
1443614436
if (const auto *S = UniquePreds.FindNodeOrInsertPos(ID, IP))
1443714437
return S;
@@ -14447,6 +14447,7 @@ const SCEVPredicate *ScalarEvolution::getWrapPredicate(
1444714447
FoldingSetNodeID ID;
1444814448
// Unique this node based on the arguments
1444914449
ID.AddInteger(SCEVPredicate::P_Wrap);
14450+
// TODO: Use SCEVUse
1445014451
ID.AddPointer(AR);
1445114452
ID.AddInteger(AddedFlags);
1445214453
void *IP = nullptr;
@@ -14960,10 +14961,10 @@ SCEVUse ScalarEvolution::computeSymbolicMaxBackedgeTakenCount(const Loop *L) {
1496014961
/// in the map. It skips AddRecExpr because we cannot guarantee that the
1496114962
/// replacement is loop invariant in the loop of the AddRec.
1496214963
class SCEVLoopGuardRewriter : public SCEVRewriteVisitor<SCEVLoopGuardRewriter> {
14963-
const DenseMap<const SCEV *, SCEVUse> &Map;
14964+
const DenseMap<SCEVUse, SCEVUse> &Map;
1496414965

1496514966
public:
14966-
SCEVLoopGuardRewriter(ScalarEvolution &SE, DenseMap<const SCEV *, SCEVUse> &M)
14967+
SCEVLoopGuardRewriter(ScalarEvolution &SE, DenseMap<SCEVUse, SCEVUse> &M)
1496714968
: SCEVRewriteVisitor(SE), Map(M) {}
1496814969

1496914970
SCEVUse visitAddRecExpr(const SCEVAddRecExpr *Expr) { return Expr; }
@@ -15026,7 +15027,7 @@ SCEVUse ScalarEvolution::applyLoopGuards(SCEVUse Expr, const Loop *L) {
1502615027
SmallVector<SCEVUse> ExprsToRewrite;
1502715028
auto CollectCondition = [&](ICmpInst::Predicate Predicate, SCEVUse LHS,
1502815029
SCEVUse RHS,
15029-
DenseMap<const SCEV *, SCEVUse> &RewriteMap) {
15030+
DenseMap<SCEVUse, SCEVUse> &RewriteMap) {
1503015031
// WARNING: It is generally unsound to apply any wrap flags to the proposed
1503115032
// replacement SCEV which isn't directly implied by the structure of that
1503215033
// SCEV. In particular, using contextual facts to imply flags is *NOT*
@@ -15396,7 +15397,7 @@ SCEVUse ScalarEvolution::applyLoopGuards(SCEVUse Expr, const Loop *L) {
1539615397
// Conditions are processed in reverse order, so the earliest conditions is
1539715398
// processed first. This ensures the SCEVs with the shortest dependency chains
1539815399
// are constructed first.
15399-
DenseMap<const SCEV *, SCEVUse> RewriteMap;
15400+
DenseMap<SCEVUse, SCEVUse> RewriteMap;
1540015401
for (auto [Term, EnterIfTrue] : reverse(Terms)) {
1540115402
SmallVector<Value *, 8> Worklist;
1540215403
SmallPtrSet<Value *, 8> Visited;

0 commit comments

Comments
 (0)