Skip to content

Commit b8da835

Browse files
dlei6gsys_zuul
authored andcommitted
Fix nested stack calls corrupting the ARG register
- Only apply optimization to alias the ARG register for leaf functions, since they do not further write to ARG. - Non-leaf functions still requires copying the ARGs to a temp register at function entry. Change-Id: I80d1ede2faa3b3ef9d05408b2574567d6e34ffcc
1 parent b69a80e commit b8da835

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10302,6 +10302,7 @@ void EmitPass::emitStackFuncEntry(Function* F)
1030210302
CVariable* ArgBlkVar = m_currShader->GetARGV();
1030310303
uint32_t offsetA = 0; // visa argument offset
1030410304
uint32_t offsetS = 0; // visa stack offset
10305+
bool isLeafFunc = getAnalysis<CallGraphWrapperPass>().getCallGraph()[F]->empty();
1030510306
std::vector<CVariable*> argsOnStack;
1030610307
for (auto& Arg : F->args())
1030710308
{
@@ -10335,12 +10336,21 @@ void EmitPass::emitStackFuncEntry(Function* F)
1033510336
Src = m_currShader->GetNewAlias(ArgBlkVar, ISA_TYPE_W, (uint16_t)offsetA, numLanes(m_currShader->m_dispatchSize), false);
1033610337
m_encoder->Cmp(EPREDICATE_NE, Dst, Src, m_currShader->ImmToVariable(0, ISA_TYPE_W));
1033710338
}
10338-
else
10339+
else if (isLeafFunc)
1033910340
{
1034010341
// Directly map the dst register to an alias of ArgBlkVar, and update symbol mapping for future uses
1034110342
Dst = m_currShader->GetNewAlias(ArgBlkVar, Dst->GetType(), (uint16_t)offsetA, Dst->GetNumberElement(), Dst->IsUniform());
1034210343
m_currShader->UpdateSymbolMap(&Arg, Dst);
1034310344
}
10345+
else
10346+
{
10347+
// For calls not guaranteed to preserve the ARG register, we copy it first to a temp
10348+
if (Src->GetType() != Dst->GetType() || offsetA != 0 || Src->IsUniform() != Dst->IsUniform())
10349+
{
10350+
Src = m_currShader->GetNewAlias(ArgBlkVar, Dst->GetType(), (uint16_t)offsetA, Dst->GetNumberElement(), Dst->IsUniform());
10351+
}
10352+
emitCopyAll(Dst, Src, Arg.getType());
10353+
}
1034410354
}
1034510355
offsetA += argSize;
1034610356
}

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636
#include <llvm/IR/DataLayout.h>
3737
#include <llvm/IR/InlineAsm.h>
3838
#include "llvm/IR/GetElementPtrTypeIterator.h"
39+
#include "llvm/Analysis/CallGraph.h"
3940
#include "common/LLVMWarningsPop.hpp"
4041
#include "Compiler/IGCPassSupport.h"
4142
#include "Probe/Assertion.h"
@@ -73,6 +74,7 @@ class EmitPass : public llvm::FunctionPass
7374
AU.addRequired<Simd32ProfitabilityAnalysis>();
7475
AU.addRequired<CodeGenContextWrapper>();
7576
AU.addRequired<VariableReuseAnalysis>();
77+
AU.addRequired<llvm::CallGraphWrapperPass>();
7678
AU.setPreservesAll();
7779
}
7880

0 commit comments

Comments
 (0)