@@ -4410,24 +4410,24 @@ const SCEV *ScalarEvolution::getPointerBase(const SCEV *V) {
4410
4410
}
4411
4411
4412
4412
/// Push users of the given Instruction onto the given Worklist.
4413
- static void
4414
- PushDefUseChildren( Instruction *I ,
4415
- SmallVectorImpl <Instruction *> &Worklist ) {
4413
+ static void PushDefUseChildren(Instruction *I,
4414
+ SmallVectorImpl< Instruction *> &Worklist ,
4415
+ SmallPtrSetImpl <Instruction *> &Visited ) {
4416
4416
// Push the def-use children onto the Worklist stack.
4417
- for (User *U : I->users())
4418
- Worklist.push_back(cast<Instruction>(U));
4417
+ for (User *U : I->users()) {
4418
+ auto *UserInsn = cast<Instruction>(U);
4419
+ if (Visited.insert(UserInsn).second)
4420
+ Worklist.push_back(UserInsn);
4421
+ }
4419
4422
}
4420
4423
4421
4424
void ScalarEvolution::forgetSymbolicName(Instruction *PN, const SCEV *SymName) {
4422
4425
SmallVector<Instruction *, 16> Worklist;
4423
- PushDefUseChildren(PN, Worklist);
4424
-
4425
4426
SmallPtrSet<Instruction *, 8> Visited;
4426
4427
Visited.insert(PN);
4428
+ Worklist.push_back(PN);
4427
4429
while (!Worklist.empty()) {
4428
4430
Instruction *I = Worklist.pop_back_val();
4429
- if (!Visited.insert(I).second)
4430
- continue;
4431
4431
4432
4432
auto It = ValueExprMap.find_as(static_cast<Value *>(I));
4433
4433
if (It != ValueExprMap.end()) {
@@ -4453,7 +4453,7 @@ void ScalarEvolution::forgetSymbolicName(Instruction *PN, const SCEV *SymName) {
4453
4453
}
4454
4454
}
4455
4455
4456
- PushDefUseChildren(I, Worklist);
4456
+ PushDefUseChildren(I, Worklist, Visited );
4457
4457
}
4458
4458
}
4459
4459
@@ -7370,13 +7370,15 @@ bool ScalarEvolution::isBackedgeTakenCountMaxOrZero(const Loop *L) {
7370
7370
}
7371
7371
7372
7372
/// Push PHI nodes in the header of the given loop onto the given Worklist.
7373
- static void
7374
- PushLoopPHIs(const Loop *L, SmallVectorImpl<Instruction *> &Worklist) {
7373
+ static void PushLoopPHIs(const Loop *L,
7374
+ SmallVectorImpl<Instruction *> &Worklist,
7375
+ SmallPtrSetImpl<Instruction *> &Visited) {
7375
7376
BasicBlock *Header = L->getHeader();
7376
7377
7377
7378
// Push all Loop-header PHIs onto the Worklist stack.
7378
7379
for (PHINode &PN : Header->phis())
7379
- Worklist.push_back(&PN);
7380
+ if (Visited.insert(&PN).second)
7381
+ Worklist.push_back(&PN);
7380
7382
}
7381
7383
7382
7384
const ScalarEvolution::BackedgeTakenInfo &
@@ -7437,9 +7439,8 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
7437
7439
// it handles SCEVUnknown PHI nodes specially.
7438
7440
if (Result.hasAnyInfo()) {
7439
7441
SmallVector<Instruction *, 16> Worklist;
7440
- PushLoopPHIs(L, Worklist);
7441
-
7442
7442
SmallPtrSet<Instruction *, 8> Discovered;
7443
+ PushLoopPHIs(L, Worklist, Discovered);
7443
7444
while (!Worklist.empty()) {
7444
7445
Instruction *I = Worklist.pop_back_val();
7445
7446
@@ -7551,12 +7552,10 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
7551
7552
}
7552
7553
7553
7554
// Drop information about expressions based on loop-header PHIs.
7554
- PushLoopPHIs(CurrL, Worklist);
7555
+ PushLoopPHIs(CurrL, Worklist, Visited );
7555
7556
7556
7557
while (!Worklist.empty()) {
7557
7558
Instruction *I = Worklist.pop_back_val();
7558
- if (!Visited.insert(I).second)
7559
- continue;
7560
7559
7561
7560
ValueExprMapType::iterator It =
7562
7561
ValueExprMap.find_as(static_cast<Value *>(I));
@@ -7567,7 +7566,7 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
7567
7566
ConstantEvolutionLoopExitValue.erase(PN);
7568
7567
}
7569
7568
7570
- PushDefUseChildren(I, Worklist);
7569
+ PushDefUseChildren(I, Worklist, Visited );
7571
7570
}
7572
7571
7573
7572
LoopPropertiesCache.erase(CurrL);
@@ -7589,14 +7588,12 @@ void ScalarEvolution::forgetValue(Value *V) {
7589
7588
7590
7589
// Drop information about expressions based on loop-header PHIs.
7591
7590
SmallVector<Instruction *, 16> Worklist;
7591
+ SmallPtrSet<Instruction *, 8> Visited;
7592
7592
Worklist.push_back(I);
7593
+ Visited.insert(I);
7593
7594
7594
- SmallPtrSet<Instruction *, 8> Visited;
7595
7595
while (!Worklist.empty()) {
7596
7596
I = Worklist.pop_back_val();
7597
- if (!Visited.insert(I).second)
7598
- continue;
7599
-
7600
7597
ValueExprMapType::iterator It =
7601
7598
ValueExprMap.find_as(static_cast<Value *>(I));
7602
7599
if (It != ValueExprMap.end()) {
@@ -7606,7 +7603,7 @@ void ScalarEvolution::forgetValue(Value *V) {
7606
7603
ConstantEvolutionLoopExitValue.erase(PN);
7607
7604
}
7608
7605
7609
- PushDefUseChildren(I, Worklist);
7606
+ PushDefUseChildren(I, Worklist, Visited );
7610
7607
}
7611
7608
}
7612
7609
0 commit comments