Skip to content

Commit 9fe158e

Browse files
dlei6gsys_zuul
authored andcommitted
- Enforce immediate value constraint for inline asm.
- Fixed a bug where the source of an inline asm call with multiple outputs was not being matched in PatternMatchPass. - Fixed an issue where LLVM promotes a variable to a constant, causing an immediate value to be written to the asm string when it should not be. __asm__ ("mov (M1, 16) %0(0,0)<1> %1(0,0)<1;1,0>" : "=rw" (s1) : "rw" (s2) ); When s2 is promoted to a constant value, the following vISA instruction is generated. The immediate value still contains the regioning info from the user inlined string. mov (M1, 16) V39(0,0)<1> 0x3f800000:f(0,0)<1;1,0> By enforcing the constraint, if we detect an immediate value with the "rw" constraint, we can generate an extra move instruction to resolve this issue. Change-Id: I6421d88b41bad8fa2915e03ccab759b1eb02428c
1 parent 97ed538 commit 9fe158e

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8140,6 +8140,8 @@ void EmitPass::EmitInlineAsm(llvm::CallInst* inst)
81408140
opnds.push_back(cv);
81418141
}
81428142

8143+
assert(opnds.size() == constraints.size());
8144+
81438145
// Check for read/write registers
81448146
if (!inst->getType()->isVoidTy())
81458147
{
@@ -8160,6 +8162,20 @@ void EmitPass::EmitInlineAsm(llvm::CallInst* inst)
81608162
}
81618163
}
81628164

8165+
// Special handling if LLVM replaces a variable with an immediate, we need to insert an extra move
8166+
for (unsigned i = 0; i < opnds.size(); i++)
8167+
{
8168+
CVariable* opVar = opnds[i];
8169+
StringRef constraint = constraints[i];
8170+
if (opVar->IsImmediate() && !constraint.equals("i"))
8171+
{
8172+
CVariable* tempMov = m_currShader->GetNewVariable(1, opVar->GetType(), EALIGN_GRF, true);
8173+
m_encoder->Copy(tempMov, opVar);
8174+
m_encoder->Push();
8175+
opnds[i] = tempMov;
8176+
}
8177+
}
8178+
81638179
str << endl << "/// Inlined ASM" << endl;
81648180
// Look for variables to replace with the VISA variable
81658181
size_t startPos = 0;

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,18 +1349,20 @@ namespace IGC
13491349
bool Match = false;
13501350

13511351
// Ignore the extract value instruction. Handled in the call inst.
1352-
bool isExtractFromInlineAsm = false;
13531352
if (CallInst * call = dyn_cast<CallInst>(I.getOperand(0)))
13541353
{
1355-
isExtractFromInlineAsm = call->isInlineAsm() && call->getType()->isStructTy();
1354+
if (call->isInlineAsm() && call->getType()->isStructTy())
1355+
{
1356+
MarkAsSource(call);
1357+
return;
1358+
}
13561359
}
13571360

1358-
Match = isExtractFromInlineAsm ||
1359-
MatchCopyFromStruct(&I) ||
1360-
matchAddPair(&I) ||
1361+
Match = matchAddPair(&I) ||
13611362
matchSubPair(&I) ||
13621363
matchMulPair(&I) ||
1363-
matchPtrToPair(&I);
1364+
matchPtrToPair(&I) ||
1365+
MatchCopyFromStruct(&I);
13641366

13651367
assert(Match && "Unknown `extractvalue` instruction!");
13661368
}

0 commit comments

Comments
 (0)