Skip to content

Commit 748987f

Browse files
bcheng0127igcbot
authored andcommitted
Fix bug of sendg
For multiple define registers, don't remove the corresponding mov instruction
1 parent 8553c8d commit 748987f

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

visa/Passes/SRSubstitution.cpp

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -669,25 +669,34 @@ bool SRSubPassAfterRA::isSRCandidateAfterRA(G4_INST *inst,
669669
return (G4_INST *)nullptr;
670670
};
671671

672-
//if opndNum + offset is defined multiple times, cannobe be removed
673-
G4_Operand *dst = movInst->getDst();
674-
unsigned offset = dst->getLeftBound() / builder.getGRFSize();
675672
// The source opndNum of send instruction which was defined
676673
Gen4_Operand_Number opndNum = (*I).second;
674+
//if opndNum + offset is defined multiple times, cannobe be removed
675+
G4_Operand *dst = movInst->getDst();
676+
// The startOffset is the offset to the declare
677+
unsigned startOffset = dst->getLeftBound() / builder.getGRFSize();
678+
unsigned dstSize = (dst->getLinearizedEnd() - dst->getLinearizedStart() +
679+
builder.getGRFSize() - 1) /
680+
builder.getGRFSize();
677681

678682
if (isRemoveAble(movInst)) {
679683
auto iter = std::find_if(
680684
dstSrcRegs.dstSrcMap.begin(), dstSrcRegs.dstSrcMap.end(),
681-
[opndNum, offset](regMapBRA regmap) {
682-
return regmap.opndNum == opndNum &&
683-
regmap.offset == offset;
684-
});
685+
[opndNum, dst](regMapBRA regmap) {
686+
return regmap.opndNum == opndNum &&
687+
!((regmap.inst->getDst()->getLinearizedStart() >
688+
dst->getLinearizedEnd()) ||
689+
(dst->getLinearizedStart() >
690+
regmap.inst->getDst()->getLinearizedEnd()));
691+
});
685692
// if multiple defined, cannot be removed
686693
if (iter != dstSrcRegs.dstSrcMap.end()) {
687-
notRemoveableMap.push_back(std::make_pair(opndNum, offset));
694+
for (unsigned offset = startOffset; offset < dstSize; offset++) {
695+
notRemoveableMap.push_back(std::make_pair(opndNum, offset));
696+
}
688697
} else {
689698
G4_Operand *src = movInst->getSrc(0);
690-
regMapBRA regPair(movInst, opndNum, offset, src);//mov source
699+
regMapBRA regPair(movInst, opndNum, startOffset, src); // mov source
691700
dstSrcRegs.dstSrcMap.push_back(regPair);
692701
firstDefID = std::min(firstDefID, def.first->getLocalId());
693702
movInstNum++;
@@ -702,15 +711,17 @@ bool SRSubPassAfterRA::isSRCandidateAfterRA(G4_INST *inst,
702711
// The offset is the offset of original dst, which is used to identify
703712
// the original register used in send.
704713
// The opndNum is the opndNum of send.
705-
regMapBRA regPair(movInst, opndNum, offset,
714+
regMapBRA regPair(movInst, opndNum, startOffset,
706715
lvnMov->getDst()); // the lvn mov dst can be reused
707716
dstSrcRegs.dstSrcMap.push_back(regPair);
708717
firstDefID = std::min(firstDefID, def.first->getLocalId());
709718
movInstNum++;
710719
continue;
711720
}
712721
}
713-
notRemoveableMap.push_back(std::make_pair(opndNum, offset));
722+
for (unsigned offset = startOffset; offset < dstSize; offset++) {
723+
notRemoveableMap.push_back(std::make_pair(opndNum, offset));
724+
}
714725
}
715726
}
716727

@@ -776,9 +787,10 @@ bool SRSubPassAfterRA::replaceWithSendiAfterRA(G4_BB *bb,
776787
bool replaced = false;
777788
if (j < (int)dstSrcRegs.dstSrcMap.size() &&
778789
dstSrcRegs.dstSrcMap[j].opndNum == Opnd_src0) {
779-
int opndSize = (dstSrcRegs.dstSrcMap[j].opnd->getLinearizedEnd() -
780-
dstSrcRegs.dstSrcMap[j].opnd->getLinearizedStart() + 1) /
781-
GRFSize;
790+
int opndSize =
791+
(dstSrcRegs.dstSrcMap[j].opnd->getLinearizedEnd() -
792+
dstSrcRegs.dstSrcMap[j].opnd->getLinearizedStart() + GRFSize - 1) /
793+
GRFSize;
782794
int srcOffset = src0->getLeftBound() / GRFSize + i;
783795
int opndOffset = dstSrcRegs.dstSrcMap[j].offset;
784796

@@ -819,9 +831,10 @@ bool SRSubPassAfterRA::replaceWithSendiAfterRA(G4_BB *bb,
819831
bool replaced = false;
820832
if (j < (int)dstSrcRegs.dstSrcMap.size() &&
821833
dstSrcRegs.dstSrcMap[j].opndNum == Opnd_src1) {
822-
int opndSize = (dstSrcRegs.dstSrcMap[j].opnd->getLinearizedEnd() -
823-
dstSrcRegs.dstSrcMap[j].opnd->getLinearizedStart() + 1) /
824-
GRFSize;
834+
int opndSize =
835+
(dstSrcRegs.dstSrcMap[j].opnd->getLinearizedEnd() -
836+
dstSrcRegs.dstSrcMap[j].opnd->getLinearizedStart() + GRFSize - 1) /
837+
GRFSize;
825838
int srcOffset = src1->getLeftBound() / GRFSize + i;
826839
int opndOffset = dstSrcRegs.dstSrcMap[j].offset;
827840

0 commit comments

Comments
 (0)