Skip to content

Commit f84d071

Browse files
teresajohnsonmemfrob
authored andcommitted
[PowerPC] Fix compile time issue in recursive CTR analysis code
Summary: Avoid re-examining operands on recursive walk looking for CTR. This was causing huge compile time after some earlier optimization created a large expression. The start of the expression (created by IndVarSimplify) looked like: %469 = lshr i64 trunc (i128 xor (i128 udiv (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 ptrtoint (i8 @_ZN4absl13hash_internal13CityHashState5kSeedE to i64), i64 120) to i128), i128 8192506886679785011), i128 64), i128 mul (i128 zext (i64 add (i64 ptrtoint (i8 @_ZN4absl13hash_internal13CityHashState5kSeedE to i64), i64 120) to i128), i128 8192506886679785011)) to i64), i64 45) to i128), i128 8192506886679785011), i128 64), i128 mul (i128 zext (i64 add (i64 trunc (i128 xor (i128 lshr (i128 mul (i128 zext (i64 add (i64 ptrtoint (i8 @_ZN4absl13hash_internal13CityHashState5kSeedE to i64), i64 120) to i128), i128 8192506886679785011), i128 64), i128 mul (i128 zext (i64 add (i64 ptrtoint (i8 @_ZN4absl13hash_internal13CityHashState5kSeedE to i64), i64 120) to i128), i128 8192506886679785011)) to i64), i64 45) to i128), ... with the _ZN4absl13hash_internal13CityHashState5kSeedE referenced many times. Reviewers: hfinkel Subscribers: nemanjai, hiraditya, kbarton, jsji, shchenz, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75790
1 parent 53d6e11 commit f84d071

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ unsigned PPCTTIImpl::getUserCost(const User *U,
217217
return BaseT::getUserCost(U, Operands);
218218
}
219219

220-
bool PPCTTIImpl::mightUseCTR(BasicBlock *BB,
221-
TargetLibraryInfo *LibInfo) {
220+
bool PPCTTIImpl::mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
221+
SmallPtrSetImpl<const Value *> &Visited) {
222222
const PPCTargetMachine &TM = ST->getTargetMachine();
223223

224224
// Loop through the inline asm constraints and look for something that
@@ -237,8 +237,11 @@ bool PPCTTIImpl::mightUseCTR(BasicBlock *BB,
237237

238238
// Determining the address of a TLS variable results in a function call in
239239
// 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;
242245
const auto *GV = dyn_cast<GlobalValue>(MemAddr);
243246
if (!GV) {
244247
// Recurse to check for constants that refer to TLS global variables.
@@ -502,9 +505,10 @@ bool PPCTTIImpl::isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE,
502505

503506
// We don't want to spill/restore the counter register, and so we don't
504507
// want to use the counter register if the loop contains calls.
508+
SmallPtrSet<const Value *, 4> Visited;
505509
for (Loop::block_iterator I = L->block_begin(), IE = L->block_end();
506510
I != IE; ++I)
507-
if (mightUseCTR(*I, LibInfo))
511+
if (mightUseCTR(*I, LibInfo, Visited))
508512
return false;
509513

510514
SmallVector<BasicBlock*, 4> ExitingBlocks;

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
3333

3434
const PPCSubtarget *getST() const { return ST; }
3535
const PPCTargetLowering *getTLI() const { return TLI; }
36-
bool mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo);
36+
bool mightUseCTR(BasicBlock *BB, TargetLibraryInfo *LibInfo,
37+
SmallPtrSetImpl<const Value *> &Visited);
3738

3839
public:
3940
explicit PPCTTIImpl(const PPCTargetMachine *TM, const Function &F)

0 commit comments

Comments
 (0)