Skip to content

Commit e1eb115

Browse files
jgu222igcbot
authored andcommitted
Hash mov fix
insert mov after EOT or at the entry. For example, (W) send.gtwy (1|M0) null r127 null:0 0x0 0x02000010 {EOT,F@1} nop (W) mov (16|M0) null<1>:ud 0x2D1D3FFE:ud (W) mov (16|M0) null<1>:ud 0xF6824120:ud (W) mov (16|M0) null<1>:ud 0x0:ud (W) mov (16|M0) null<1>:ud 0x4:ud This change: 1. make sure the hash mov order is as below: mov hashmovs's hi mov hashmovs's lo [mov hashmovs1's hi mov hashmovs1's lo] hashmovs1 is optional. Previously, visa did "mov lo" first before "mov hi". This change makes sure hi goes before lo to be consistent with flag. Also, scalar IGC generates "hashmovs/hashmovs1 lo hi", which has the wrong order of hi and lo. This change also fixed that. 2. For OCL, use kernel dump id as hashmovs1's lo, and set its hi to zero. For example, a dump kernel: OCL_asmf68241202d1d3ffe_simd16_entry_0005.asm, it has: hashmovs1's lo = 5. hashmovs1's hi = 0.
1 parent 395a236 commit e1eb115

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,22 +3832,29 @@ namespace IGC
38323832
params.push_back(param_uptr(OptName, literal_deleter));
38333833
std::string Low = std::to_string((DWORD)Hash);
38343834
std::string High = std::to_string((DWORD)(Hash >> 32));
3835-
params.push_back(param_uptr(_strdup(Low.c_str()), dup_deleter));
38363835
params.push_back(param_uptr(_strdup(High.c_str()), dup_deleter));
3836+
params.push_back(param_uptr(_strdup(Low.c_str()), dup_deleter));
38373837
};
38383838

38393839
QWORD AssemblyHash = context->hash.getAsmHash();
38403840

38413841

38423842
addHash("-hashmovs", AssemblyHash);
3843+
if (context->type == ShaderType::OPENCL_SHADER)
3844+
{
3845+
uint32_t kernelId = context->getFunctionID(m_program->entry);
3846+
addHash("-hashmovs1", (QWORD)kernelId);
3847+
}
3848+
else {
38433849

3844-
QWORD NosHash = context->hash.getNosHash();
3845-
QWORD PsoHash = context->hash.getPsoHash();
3846-
QWORD hashToUse = NosHash != 0 ? NosHash : PsoHash;
3847-
if (hashToUse)
3848-
addHash("-hashmovs1", hashToUse);
3849-
else if (context->hash.getPerShaderPsoHash() != 0)
3850-
addHash("-hashmovs1", context->hash.getPerShaderPsoHash());
3850+
QWORD NosHash = context->hash.getNosHash();
3851+
QWORD PsoHash = context->hash.getPsoHash();
3852+
QWORD hashToUse = NosHash != 0 ? NosHash : PsoHash;
3853+
if (hashToUse)
3854+
addHash("-hashmovs1", hashToUse);
3855+
else if (context->hash.getPerShaderPsoHash() != 0)
3856+
addHash("-hashmovs1", context->hash.getPerShaderPsoHash());
3857+
}
38513858
}
38523859
}
38533860

visa/Optimizer.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ void Optimizer::insertHashMovs() {
326326
for (auto it = bb->begin(); it != bb->end(); ++it) {
327327
auto inst = (*it);
328328
if (inst->isEOT() || hashAtPrologue) {
329+
auto insertBefore = it;
330+
if (inst->isLabel())
331+
++insertBefore;
329332
// We have to insert new instructions after EOT.
330333
// Lexically, EOT could even be in the middle
331334
// of the program.
332335
auto insertHashMovInsts = [&](uint64_t hashVal) {
333-
if (hashVal == 0)
334-
return;
335-
336336
G4_INST *lo;
337337
G4_INST *hi;
338338
lo = kernel.fg.builder->createMov(
@@ -346,29 +346,26 @@ void Optimizer::insertHashMovs() {
346346
kernel.fg.builder->createImm(
347347
(unsigned int)((hashVal >> 32) & 0xffffffff), Type_UD),
348348
InstOpt_WriteEnable, false);
349-
349+
// Option: -hashmovs hi lo
350+
// To be consistent, 'mov hi' goes before 'mov lo'
350351
if (hashAtPrologue) {
351-
if (inst->isLabel()) {
352-
bb->insertAfter(it, hi);
353-
bb->insertAfter(it, lo);
354-
} else {
355-
bb->insertBefore(it, hi);
356-
bb->insertBefore(it, lo);
357-
}
352+
bb->insertBefore(insertBefore, hi);
353+
bb->insertBefore(insertBefore, lo);
358354
} else {
359-
bb->push_back(lo);
360355
bb->push_back(hi);
356+
bb->push_back(lo);
361357
}
362358
};
363-
uint64_t hashVal1 = builder.getOptions()->getuInt64Option(vISA_HashVal);
364-
uint64_t hashVal2 =
359+
360+
// This func is called when vISA_HashVal is set by user;
361+
// but vISA_HashVal1 is still optional.
362+
uint64_t hashVal = builder.getOptions()->getuInt64Option(vISA_HashVal);
363+
insertHashMovInsts(hashVal);
364+
if (builder.getOptions()->isOptionSetByUser(vISA_HashVal1)) {
365+
uint64_t hashVal1 =
365366
builder.getOptions()->getuInt64Option(vISA_HashVal1);
366-
// Ensure same order (hashVal1 then hashVal2) by swapping if
367-
// we're going to insertAfter().
368-
if (hashAtPrologue && inst->isLabel())
369-
std::swap(hashVal1, hashVal2);
370-
insertHashMovInsts(hashVal1);
371-
insertHashMovInsts(hashVal2);
367+
insertHashMovInsts(hashVal1);
368+
}
372369
return;
373370
}
374371
}

0 commit comments

Comments
 (0)