Skip to content

Commit ee76d79

Browse files
anikaushikigcbot
authored andcommitted
Expand logic for reusing immediate values for send instructions
Extend logic in EmitVISAPass to identify reuse opportunities for constant data payload. New reuse routine for typed data payloads.
1 parent 58627e4 commit ee76d79

File tree

2 files changed

+76
-14
lines changed

2 files changed

+76
-14
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12056,13 +12056,53 @@ CVariable* EmitPass::BroadcastIfUniform(CVariable* pVar, bool nomask)
1205612056
return pVar;
1205712057
}
1205812058

12059+
CVariable* EmitPass::tryReusingXYZWPayload(Value* storedVal, BasicBlock* BB,
12060+
unsigned numElems, VISA_Type type, CVariable* pSrc_X, CVariable* pSrc_Y,
12061+
CVariable* pSrc_Z, CVariable* pSrc_W, const unsigned int numEltGRF)
12062+
{
12063+
Constant* constantStoredVal = dyn_cast<Constant>(storedVal);
12064+
if (!constantStoredVal ||
12065+
!(constantStoredVal->getType()->isFPOrFPVectorTy() ||
12066+
constantStoredVal->getType()->isIntOrIntVectorTy()))
12067+
{
12068+
return nullptr;
12069+
}
12070+
12071+
ConstVectorStoreData& storeData = m_constantVectorStores[constantStoredVal];
12072+
if (storeData.BB != BB)
12073+
{
12074+
// Make an entry of this store data with BB in the constant vector stores
12075+
storeData = {
12076+
m_currShader->GetNewVariable(
12077+
numElems,
12078+
type,
12079+
EALIGN_GRF,
12080+
CName::NONE), {nullptr, nullptr}, BB};
12081+
12082+
m_currShader->CopyVariable(storeData.var, pSrc_X, 0);
12083+
m_currShader->CopyVariable(storeData.var, pSrc_Y, numEltGRF);
12084+
m_currShader->CopyVariable(storeData.var, pSrc_Z, 2 * numEltGRF);
12085+
m_currShader->CopyVariable(storeData.var, pSrc_W, 3 * numEltGRF);
12086+
}
12087+
12088+
CVariable* broadcastedVar = storeData.broadcastedVar[m_encoder->IsSecondHalf()];
12089+
if (!broadcastedVar)
12090+
{
12091+
broadcastedVar = BroadcastIfUniform(storeData.var);
12092+
storeData.broadcastedVar[m_encoder->IsSecondHalf()] = broadcastedVar;
12093+
}
12094+
return broadcastedVar;
12095+
}
12096+
1205912097
// If constant vector is stored and there is already var instance for it
1206012098
// try reusing it (if it was defined in the same basic block)
1206112099
// or create a new var instance and make it available for reusing in further stores
1206212100
CVariable* EmitPass::tryReusingConstVectorStoreData(Value* storedVal, BasicBlock* BB, bool isBroadcast)
1206312101
{
1206412102
Constant* constantStoredVal = dyn_cast<Constant>(storedVal);
12065-
if (!constantStoredVal || !constantStoredVal->getType()->isVectorTy())
12103+
if (!constantStoredVal ||
12104+
!(constantStoredVal->getType()->isFPOrFPVectorTy() ||
12105+
constantStoredVal->getType()->isIntOrIntVectorTy()))
1206612106
{
1206712107
return nullptr;
1206812108
}
@@ -12072,7 +12112,6 @@ CVariable* EmitPass::tryReusingConstVectorStoreData(Value* storedVal, BasicBlock
1207212112
{
1207312113
// the variable is not yet created or has different BB, create the new instance
1207412114
storeData = {GetSymbol(constantStoredVal), {nullptr, nullptr}, BB};
12075-
IGC_ASSERT(!isBroadcast); // if we need broadcast we must have already created it for this store
1207612115
}
1207712116

1207812117
if (!isBroadcast)
@@ -14880,16 +14919,33 @@ void EmitPass::emitTypedWrite(llvm::Instruction* pInsn)
1488014919

1488114920
if (!needsSplit)
1488214921
{
14883-
CVariable* pPayload = m_currShader->GetNewVariable(
14884-
parameterLength * numLanes(m_currShader->m_SIMDSize),
14885-
ISA_TYPE_F,
14886-
EALIGN_GRF,
14887-
CName::NONE);
14888-
// pSrcX, Y, Z & W are broadcast to uniform by this function itself.
14889-
m_currShader->CopyVariable(pPayload, pSrc_X, 0);
14890-
m_currShader->CopyVariable(pPayload, pSrc_Y, 1);
14891-
m_currShader->CopyVariable(pPayload, pSrc_Z, 2);
14892-
m_currShader->CopyVariable(pPayload, pSrc_W, 3);
14922+
Constant* p_X = dyn_cast<Constant>(pllSrc_X);
14923+
Constant* p_Y = dyn_cast<Constant>(pllSrc_Y);
14924+
Constant* p_Z = dyn_cast<Constant>(pllSrc_Z);
14925+
Constant* p_W = dyn_cast<Constant>(pllSrc_W);
14926+
14927+
CVariable* pPayload = nullptr;
14928+
if (p_X && p_Y && p_Z && p_W) {
14929+
// if x, y, z, w are constants, find opportunities to reuse
14930+
std::vector<Constant*> xyzwPayload{ p_X, p_Y, p_Z, p_W };
14931+
llvm::Constant* payloadConstant = llvm::ConstantVector::get(xyzwPayload);
14932+
pPayload = tryReusingXYZWPayload(payloadConstant, pInsn->getParent(),
14933+
parameterLength * numLanes(m_currShader->m_SIMDSize), ISA_TYPE_F,
14934+
pSrc_X, pSrc_Y, pSrc_Z, pSrc_W, 1);
14935+
}
14936+
14937+
if (!pPayload) {
14938+
pPayload = m_currShader->GetNewVariable(
14939+
parameterLength * numLanes(m_currShader->m_SIMDSize),
14940+
ISA_TYPE_F,
14941+
EALIGN_GRF,
14942+
CName::NONE);
14943+
// pSrcX, Y, Z & W are broadcast to uniform by this function itself.
14944+
m_currShader->CopyVariable(pPayload, pSrc_X, 0);
14945+
m_currShader->CopyVariable(pPayload, pSrc_Y, 1);
14946+
m_currShader->CopyVariable(pPayload, pSrc_Z, 2);
14947+
m_currShader->CopyVariable(pPayload, pSrc_W, 3);
14948+
}
1489314949
m_encoder->SetPredicate(flag);
1489414950
m_encoder->TypedWrite4(resource, pU, pV, pR, pLOD, pPayload, writeMask);
1489514951

@@ -22321,4 +22377,5 @@ void EmitPass::emitStackOverflowDetectionCall(Function* ParentFunction) {
2232122377

2232222378
m_encoder->SubroutineCall(nullptr, StackOverflowDetectionFunction);
2232322379
m_encoder->Push();
22324-
}
22380+
}
22381+

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,12 @@ class EmitPass : public llvm::FunctionPass
878878
// If constant vector is stored and there is already var instance for it
879879
// try reusing it (if it was defined in the same basic block)
880880
// or create a new var instance and make it available for reusing in further stores
881-
CVariable* tryReusingConstVectorStoreData(llvm::Value* storedVal, llvm::BasicBlock* BB, bool isBroadcast);
881+
CVariable* tryReusingConstVectorStoreData(llvm::Value* storedVal,
882+
llvm::BasicBlock* BB, bool isBroadcast);
883+
884+
CVariable* tryReusingXYZWPayload(llvm::Value* storedVal,
885+
llvm::BasicBlock* BB, unsigned numElems, VISA_Type type, CVariable* pSrc_X,
886+
CVariable* pSrc_Y, CVariable* pSrc_Z, CVariable* pSrc_W, const unsigned int numEltGRF);
882887

883888
// Emit code in slice starting from (reverse) iterator I. Return the
884889
// iterator to the next pattern to emit.

0 commit comments

Comments
 (0)