Skip to content

Commit

Permalink
Move private memory usage detection to PrivateMemoryResolution
Browse files Browse the repository at this point in the history
Previously detection was placed in LowerGEPForPrivMem, which could be not
correct if PromoteMemoryToRegister menaged to promote given alloca. This
could cause situation where PromoteMemoryToRegister removed last alloca
in shader, meaning potential later spill/fill should be stored in slot0
instead of slot1, but detection mechanism still would force using slot1.
This would lead to situation where UMD programs only slot0, but spills
are written to slot1, causing crash.
  • Loading branch information
skarczew authored and igcbot committed Sep 22, 2023
1 parent 65d0f03 commit 36a96a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
13 changes: 0 additions & 13 deletions IGC/Compiler/CISACodeGen/LowerGEPForPrivMem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,6 @@ void LowerGEPForPrivMem::MarkNotPromtedAllocas(llvm::AllocaInst& I, IGC::StatusP
I.getContext(),
MDString::get(I.getContext(), reason));


auto allocationSize = I.getAllocationSizeInBits(m_ctx->getModule()->getDataLayout());

if (allocationSize)
{
auto scratchUsage_i = m_ctx->m_ScratchSpaceUsage.find(I.getFunction());
if (scratchUsage_i == m_ctx->m_ScratchSpaceUsage.end())
{
m_ctx->m_ScratchSpaceUsage.insert({ I.getFunction(), 0 });
}
m_ctx->m_ScratchSpaceUsage[I.getFunction()] += allocationSize.getValue() / 8;
}

UserAddrSpaceMD& userASMD = m_ctx->m_UserAddrSpaceMD;
std::function<void(Instruction*, MDNode*)> markAS_PRIV;
markAS_PRIV = [&markAS_PRIV, &userASMD](Instruction* instr, MDNode* node) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,21 @@ bool PrivateMemoryResolution::resolveAllocaInstructions(bool privateOnStack)
return false;
}

for (AllocaInst* aInst : allocaInsts)
{
auto allocationSize = aInst->getAllocationSizeInBits(m_currFunction->getParent()->getDataLayout());

if (allocationSize)
{
auto scratchUsage_i = Ctx.m_ScratchSpaceUsage.find(m_currFunction);
if (scratchUsage_i == Ctx.m_ScratchSpaceUsage.end())
{
Ctx.m_ScratchSpaceUsage.insert({ m_currFunction, 0 });
}
Ctx.m_ScratchSpaceUsage[m_currFunction] += allocationSize.getValue() / 8;
}
}

if (Ctx.m_instrTypes.numAllocaInsts > IGC_GET_FLAG_VALUE(AllocaRAPressureThreshold))
{
sinkAllocaSingleUse(allocaInsts);
Expand Down

0 comments on commit 36a96a7

Please sign in to comment.