Skip to content

Commit

Permalink
[Autobackout][FuncReg]Revert of change: 8578146
Browse files Browse the repository at this point in the history
 Reuse constant vector payload for subsequent stores

Reuse constant vector payload for subsequent stores when possible
  • Loading branch information
admitric authored and igcbot committed Jun 30, 2023
1 parent 6e91a80 commit 59cf892
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
42 changes: 3 additions & 39 deletions IGC/Compiler/CISACodeGen/EmitVISAPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11271,7 +11271,6 @@ void EmitPass::emitStoreRawIndexed(
varOffset,
immOffset,
pValToStore,
inst->getParent(),
cacheOpts,
inst->getAlignment(),
false);
Expand Down Expand Up @@ -11456,7 +11455,6 @@ void EmitPass::emitStore(
varOffset,
immOffset,
inst->getValueOperand(),
inst->getParent(),
cacheOpts,
IGCLLVM::getAlignmentValue(inst),
inst->getMetadata("enable.vmask"));
Expand Down Expand Up @@ -18186,16 +18184,15 @@ void EmitPass::emitLSCVectorStore_uniform(
void EmitPass::emitLSCVectorStore(
Value* Ptr,
Value* varOffset, ConstantInt* immOffset,
Value* storedVal, BasicBlock* BB,
LSC_CACHE_OPTS cacheOpts, alignment_t align, bool dontForceDmask)
Value* storedVal, LSC_CACHE_OPTS cacheOpts, alignment_t align, bool dontForceDmask)
{
PointerType* ptrType = cast<PointerType>(Ptr->getType());
Type* Ty = storedVal->getType();
IGCLLVM::FixedVectorType* VTy = dyn_cast<IGCLLVM::FixedVectorType>(Ty);
Type* eltTy = VTy ? VTy->getElementType() : Ty;
uint32_t eltBytes = GetScalarTypeSizeInRegister(eltTy);
uint32_t elts = VTy ? int_cast<uint32_t>(VTy->getNumElements()) : 1;

CVariable* storedVar = GetSymbol(storedVal);
unsigned int width = numLanes(m_currShader->m_SIMDSize);

ResourceDescriptor resource = GetResourceVariable(Ptr);
Expand Down Expand Up @@ -18227,28 +18224,6 @@ void EmitPass::emitLSCVectorStore(
// when true, one simd instance is generated only!
bool isOCLUniform = isUniformStoreOCL(varOffset, storedVal);

CVariable* storedVar;

// If constant vector is stored and there is already var instance for it
// try reusing it (if it was defined in the same basic block)
// or create a new var instance and make it available for reusing in further stores
Constant* constantStoredVal = dyn_cast<Constant>(storedVal);
ConstVectorStoreData* constVectorData = nullptr;
if (constantStoredVal && constantStoredVal->getType()->isVectorTy())
{
if (!m_constantVectorStores.count(constantStoredVal) ||
!(m_constantVectorStores[constantStoredVal].BB == BB))
{
m_constantVectorStores[constantStoredVal] = {GetSymbol(storedVal), nullptr, BB};
}
constVectorData = &m_constantVectorStores[constantStoredVal];
storedVar = constVectorData->var;
}
else
{
storedVar = GetSymbol(storedVal);
}

// In case eOffset isn't GRF aligned, need to create a copy
// For non-uniform variable, it should be already GRF-aligned.
eOffset = ReAlignUniformVariable(eOffset, EALIGN_GRF);
Expand Down Expand Up @@ -18285,18 +18260,7 @@ void EmitPass::emitLSCVectorStore(
VecMessInfo.getLSCInfo(Ty, align, m_currShader->GetContext(), useA32, false);

eOffset = BroadcastIfUniform(eOffset);

// try reusing the old broadcasted data as well
if (constVectorData)
{
storedVar = constVectorData->broadcastedVar ?
constVectorData->broadcastedVar : BroadcastIfUniform(storedVar);
constVectorData->broadcastedVar = storedVar;
}
else
{
storedVar = BroadcastIfUniform(storedVar);
}
storedVar = BroadcastIfUniform(storedVar);

ResourceLoop(resource, [&](CVariable* flag) {
for (uint32_t i = 0; i < VecMessInfo.numInsts; ++i)
Expand Down
10 changes: 1 addition & 9 deletions IGC/Compiler/CISACodeGen/EmitVISAPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ class EmitPass : public llvm::FunctionPass
uint64_t align);
void emitLSCVectorStore(llvm::Value *Ptr,
llvm::Value *offset, llvm::ConstantInt *immOffset,
llvm::Value *storedVal, llvm::BasicBlock* BB,
LSC_CACHE_OPTS cacheOpts,
llvm::Value *storedVal, LSC_CACHE_OPTS cacheOpts,
alignment_t align, bool dontForceDMask);
void emitGenISACopy(llvm::GenIntrinsicInst* GenCopyInst);
void emitUniformVectorCopy(CVariable* Dst, CVariable* Src, uint32_t nElts,
Expand Down Expand Up @@ -957,13 +956,6 @@ class EmitPass : public llvm::FunctionPass
bool m_isDuplicate;
CVariable *m_tmpDest = nullptr;
std::set<CoalescingEngine::CCTuple *> lifetimeStartAdded;

typedef struct {
CVariable* var;
CVariable* broadcastedVar;
llvm::BasicBlock* BB;
} ConstVectorStoreData;
llvm::DenseMap<llvm::Constant*, ConstVectorStoreData> m_constantVectorStores;
};

} // namespace IGC

0 comments on commit 59cf892

Please sign in to comment.