Skip to content

Commit

Permalink
Relax earlier restriction on rematerialization of spilled raw
Browse files Browse the repository at this point in the history
mov with immediate source

Earlier, we had a restriction where only raw movs with imm src could be
rematerialized on spill. This prevented us from rematerializing simple
cases where src imm is :w whereas dst is :d. With this change, we relax
the restriction and allow rematerialization of non-raw movs too.
  • Loading branch information
pratikashar authored and igcbot committed Sep 21, 2023
1 parent ac89a1d commit 501e2ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 8 additions & 5 deletions visa/SpillManagerGMRF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3143,16 +3143,16 @@ bool SpillManagerGRF::immFill(G4_SrcRegRegion *filledRegion,
tempDcl = std::get<1>(nearbyFill)->getDst()->getTopDcl();
} else {
// re-materialize the scalar immediate value
auto imm = sisIt->second;
tempDcl = builder_->createTempVar(1, imm->getType(),
spillDcl->getSubRegAlign());
auto dstType = sisIt->second.first;
auto *imm = sisIt->second.second;
tempDcl = builder_->createTempVar(1, dstType, spillDcl->getSubRegAlign());
auto movInst = builder_->createMov(
g4::SIMD1, builder_->createDstRegRegion(tempDcl, 1), imm,
InstOpt_WriteEnable, false);
bb->insertBefore(filledInstIter, movInst);
nearbyFill = std::make_tuple(bb, movInst, inst->getLexicalId());
// tempDcl is fill dcl that rematerializes scalar immediate.
// If tempDcl.spills in later RA iteration we shouln't
// If tempDcl spills in later RA iteration we shouldn't
// try to rematerialize the value. Instead we should
// insert regular spill/fill code for it.
gra.scalarSpills.insert(tempDcl);
Expand Down Expand Up @@ -4056,6 +4056,8 @@ void SpillManagerGRF::immMovSpillAnalysis() {

for (auto bb : gra.kernel.fg) {
for (auto inst : *bb) {
if (inst->isPseudoKill())
continue;
auto dst = inst->getDst();
auto dcl = dst && dst->getTopDcl() ? dst->getTopDcl()->getRootDeclare()
: nullptr;
Expand All @@ -4071,7 +4073,8 @@ void SpillManagerGRF::immMovSpillAnalysis() {
}
spilledDcl.insert(dcl);
if (immFillCandidate(inst)) {
scalarImmSpill[dcl] = inst->getSrc(0)->asImm();
scalarImmSpill[dcl] =
std::make_pair(dst->getType(), inst->getSrc(0)->asImm());
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions visa/SpillManagerGMRF.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,8 @@ class SpillManagerGRF {
bool avoidDstSrcOverlap_;
// spilled declares that represent a scalar immediate (created due to encoding
// restrictions) We rematerialize the immediate value instead of spill/fill
// them
std::unordered_map<G4_Declare *, G4_Imm *> scalarImmSpill;
// them. Map stores type used on dst that defined the immediate.
std::unordered_map<G4_Declare *, std::pair<G4_Type, G4_Imm *>> scalarImmSpill;
// distance to reuse filled scalar imm
const unsigned int scalarImmReuseDistance = 10;
// use cache to reuse filled scalar immediates for nearby uses
Expand Down Expand Up @@ -723,11 +723,10 @@ static inline bool isPartialRegion(REGION_TYPE *region, unsigned execSize) {
// Return true if inst is a simple mov with exec size == 1 and imm as src0.
// Def of such instructions are trivially fillable.
static bool immFillCandidate(G4_INST *inst) {
auto src0 = inst->getSrc(0);
return inst->opcode() == G4_mov && inst->getExecSize() == g4::SIMD1 &&
inst->getSrc(0)->isImm() && inst->isWriteEnableInst() &&
inst->getDst()->getType() == inst->getSrc(0)->getType() &&
!inst->getPredicate() && !inst->getCondMod() && !inst->getSaturate() &&
!inst->getSrc(0)->isRelocImm();
src0->isImm() && inst->isWriteEnableInst() && !inst->getPredicate() &&
!inst->getCondMod() && !inst->getSaturate() && !src0->isRelocImm();
}

G4_SrcRegRegion *getSpillFillHeader(IR_Builder &builder, G4_Declare *decl);
Expand Down

0 comments on commit 501e2ed

Please sign in to comment.