Skip to content

Commit 45f3750

Browse files
pratikasharpszymich
authored andcommitted
Use larger data type to avoid overflow
uint16_t was used to get scratch space offset. Largest value that can be encoded for this type is 65536. Each scratch slot using HWord message is 32 bytes. So uint16_t usage is correct only up to 2048 HWord slots. When later sHWord slots are accessed, uint16_t goes OOB. This causes dependency check to become incorrect. Fix is to use larger size (uint32_t) that can never go OOB. (cherry picked from commit 10f146f)
1 parent 47e7cc7 commit 45f3750

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

visa/LocalScheduler/Dependencies_G4IR.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ static DepType DoMemoryInterfereScratchSend(G4_INST *send1, G4_INST *send2,
140140
(depT == RET_WAW && !send1IsRead && !send2IsRead) ||
141141
(depT == RET_RAW && !send1IsRead && send2IsRead)) {
142142
// scratch guaranteed to return valid linear ImmOff
143-
uint16_t leftOff1 = (uint16_t)send1->getMsgDesc()->getOffset()->immOff;
144-
uint16_t leftOff2 = (uint16_t)send2->getMsgDesc()->getOffset()->immOff;
143+
uint32_t leftOff1 = (uint32_t)send1->getMsgDesc()->getOffset()->immOff;
144+
uint32_t leftOff2 = (uint32_t)send2->getMsgDesc()->getOffset()->immOff;
145145
auto bytesAccessed = [](const G4_INST *send) {
146146
return send->getMsgDesc()->isRead()
147147
? (uint16_t)send->getMsgDesc()->getDstLenBytes()
148148
: (uint16_t)send->getMsgDesc()->getSrc1LenBytes();
149149
};
150-
uint16_t rightOff1 = leftOff1 + bytesAccessed(send1) - 1;
151-
uint16_t rightOff2 = leftOff2 + bytesAccessed(send2) - 1;
150+
uint32_t rightOff1 = leftOff1 + bytesAccessed(send1) - 1;
151+
uint32_t rightOff2 = leftOff2 + bytesAccessed(send2) - 1;
152152
if (leftOff1 > rightOff2 || leftOff2 > rightOff1) {
153153
return NODEP;
154154
}

0 commit comments

Comments
 (0)