Skip to content

Commit d5a267d

Browse files
committed
Updated per review
1 parent 6710876 commit d5a267d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,17 @@ static void countNumMemAccesses(const Value *Ptr, unsigned &NumStores,
7474
}
7575
}
7676

77-
static void getNumGEPIndexUses(const Value *V, unsigned &NumGEPIdxUses) {
77+
static bool usedAsGEPIndex(const Value *V) {
78+
assert(V->getType()->isIntegerTy() && "Expected an integer value.");
7879
for (const User *U : V->users()) {
79-
if (const auto *LI = dyn_cast<LoadInst>(U)) {
80-
assert(isa<AllocaInst>(V) && LI->getType()->isIntegerTy() &&
81-
"Expected a load only from the alloca, with integer type.");
82-
getNumGEPIndexUses(LI, NumGEPIdxUses);
83-
}
84-
else if (const auto *SExtI = dyn_cast<SExtInst>(U))
85-
getNumGEPIndexUses(SExtI, NumGEPIdxUses);
80+
if (const auto *SExtI = dyn_cast<SExtInst>(U))
81+
return usedAsGEPIndex(SExtI);
8682
else if (const auto *ZExtI = dyn_cast<ZExtInst>(U))
87-
getNumGEPIndexUses(ZExtI, NumGEPIdxUses);
83+
return usedAsGEPIndex(ZExtI);
8884
else if (isa<GetElementPtrInst>(U))
89-
NumGEPIdxUses++;
85+
return true;
9086
}
87+
return false;
9188
}
9289

9390
// Return true if Arg is used in a Load; Add/Sub; Store sequence.
@@ -172,9 +169,14 @@ unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
172169
Argument *CalleeArg = Callee->getArg(OpIdx);
173170
if (const AllocaInst *AI = dyn_cast<AllocaInst>(CallerArg))
174171
if (AI->getAllocatedType()->isIntegerTy() && !AI->isArrayAllocation()) {
175-
unsigned NumGEPIdxUses = 0;
176-
getNumGEPIndexUses(AI, NumGEPIdxUses);
177-
if (NumGEPIdxUses && looksLikeIVUpdate(Callee, CalleeArg)) {
172+
bool UsedAsGEPIndex = false;
173+
for (const User *U : AI->users())
174+
if (const auto *LI = dyn_cast<LoadInst>(U))
175+
if (usedAsGEPIndex(LI)) {
176+
UsedAsGEPIndex = true;
177+
break;
178+
}
179+
if (UsedAsGEPIndex && looksLikeIVUpdate(Callee, CalleeArg)) {
178180
Bonus = 1000;
179181
break;
180182
}

0 commit comments

Comments
 (0)