Skip to content
23 changes: 23 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ static cl::opt<unsigned>
"when sorting profitable allocas"),
cl::init(4));

static cl::opt<unsigned> PromoteAllocaDynamicIndexNumberElementLimit(
"amdgpu-promote-alloca-dynamic-index-num-element-limit",
cl::desc("Maximum number of elements for promoting alloca with dynamic"
" index"),
cl::init(8));

// Shared implementation which can do both promotion to vector and to LDS.
class AMDGPUPromoteAllocaImpl {
private:
Expand Down Expand Up @@ -920,6 +926,23 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
if (!Index)
return RejectUser(Inst, "cannot compute vector index for GEP");

auto Predicate = [&](const User *U) -> bool {
if (auto *LI = dyn_cast<LoadInst>(U)) {
if (auto *LoadVecTy = dyn_cast<FixedVectorType>(LI->getType())) {
if (LoadVecTy->getNumElements() >
PromoteAllocaDynamicIndexNumberElementLimit)
return true;
}
}
return false;
};
if (!isa<ConstantInt>(Index)) {
if (llvm::any_of(GEP->users(), Predicate)) {
return RejectUser(Inst,
"user has too many elements for dynamic index");
}
}

GEPVectorIdx[GEP] = Index;
UsersToRemove.push_back(Inst);
continue;
Expand Down
Loading
Loading