@@ -217,8 +217,8 @@ unsigned PPCTTIImpl::getUserCost(const User *U,
217
217
return BaseT::getUserCost (U, Operands);
218
218
}
219
219
220
- bool PPCTTIImpl::mightUseCTR (BasicBlock *BB,
221
- TargetLibraryInfo *LibInfo ) {
220
+ bool PPCTTIImpl::mightUseCTR (BasicBlock *BB, TargetLibraryInfo *LibInfo,
221
+ SmallPtrSetImpl< const Value *> &Visited ) {
222
222
const PPCTargetMachine &TM = ST->getTargetMachine ();
223
223
224
224
// Loop through the inline asm constraints and look for something that
@@ -237,8 +237,11 @@ bool PPCTTIImpl::mightUseCTR(BasicBlock *BB,
237
237
238
238
// Determining the address of a TLS variable results in a function call in
239
239
// certain TLS models.
240
- std::function<bool (const Value*)> memAddrUsesCTR =
241
- [&memAddrUsesCTR, &TM](const Value *MemAddr) -> bool {
240
+ std::function<bool (const Value *)> memAddrUsesCTR =
241
+ [&memAddrUsesCTR, &TM, &Visited](const Value *MemAddr) -> bool {
242
+ // No need to traverse again if we already checked this operand.
243
+ if (!Visited.insert (MemAddr).second )
244
+ return false ;
242
245
const auto *GV = dyn_cast<GlobalValue>(MemAddr);
243
246
if (!GV) {
244
247
// Recurse to check for constants that refer to TLS global variables.
@@ -502,9 +505,10 @@ bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
502
505
503
506
// We don't want to spill/restore the counter register, and so we don't
504
507
// want to use the counter register if the loop contains calls.
508
+ SmallPtrSet<const Value *, 4 > Visited;
505
509
for (Loop::block_iterator I = L->block_begin (), IE = L->block_end ();
506
510
I != IE; ++I)
507
- if (mightUseCTR (*I, LibInfo))
511
+ if (mightUseCTR (*I, LibInfo, Visited ))
508
512
return false ;
509
513
510
514
SmallVector<BasicBlock*, 4 > ExitingBlocks;
0 commit comments