Skip to content

Commit 02a1e3f

Browse files
bcheng0127igcbot
authored andcommitted
Linear Scan RA bug: avoid dst/src overlap for define only and use only variables
For define only and use only variables, since the live ranges are not overlap, linear scan RA may allow dst and src use same register. Extend liverange of dst 1 to create liverange overlap and avoid same register assigned.
1 parent 067150b commit 02a1e3f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

visa/LinearScanRA.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,11 @@ void LinearScanRA::setDstReferences(
11651165
if (lr->getFirstRef(startIdx) == NULL && startIdx == 0) {
11661166
lr->setFirstRef(curInst, curInst->getLexicalId() * 2);
11671167
}
1168-
lr->setLastRef(curInst, curInst->getLexicalId() * 2);
1168+
1169+
// For dst, we set the last ref = lexcial_ID * 2 + 1.
1170+
// So that the dst will not be released immediately if it's defined only.
1171+
// This is to handle some special workload. Such as for LIT test
1172+
lr->setLastRef(curInst, curInst->getLexicalId() * 2 + 1);
11691173
} else if (dcl->getRegVar()
11701174
->getPhyReg()
11711175
->isGreg()) // Assigned already and is GRF
@@ -1184,7 +1188,9 @@ void LinearScanRA::setDstReferences(
11841188
if (lr->getFirstRef(startIdx) == NULL && startIdx == 0) {
11851189
lr->setFirstRef(curInst, curInst->getLexicalId() * 2);
11861190
}
1187-
lr->setLastRef(curInst, curInst->getLexicalId() * 2);
1191+
// For dst, we set the last ref = lexcial_ID * 2 + 1.
1192+
// So that the dst will not be released immediately if it's defined only.
1193+
lr->setLastRef(curInst, curInst->getLexicalId() * 2 + 1);
11881194
}
11891195

11901196
if (lr->isEOT() && std::find(eotLiveIntervals.begin(), eotLiveIntervals.end(),
@@ -1281,7 +1287,10 @@ void LinearScanRA::generateInputIntervals(
12811287
unsigned int idx = regNum * builder.numEltPerGRF<Type_UW>() +
12821288
(regOff * topdcl->getElemSize()) / G4_WSIZE +
12831289
topdcl->getWordSize() - 1;
1284-
1290+
//Variable size may be larger than occupied GRF
1291+
if (idx > (kernel.getNumRegTotal() * builder.numEltPerGRF<Type_UW>() - 1)) {
1292+
idx = kernel.getNumRegTotal() * builder.numEltPerGRF<Type_UW>() - 1;
1293+
}
12851294
unsigned int numWords = topdcl->getWordSize();
12861295
for (int i = numWords - 1; i >= 0; --i, --idx) {
12871296
if ((inputRegLastRef[idx] == UINT_MAX || inputRegLastRef[idx] < instID) &&

0 commit comments

Comments
 (0)