Skip to content

Commit 8dc78be

Browse files
committed
Fix a bug in shareBuffers
If an @out parameter is also used as @in by an instruction, add it the the live buffers set. This bug was detected by the liveness verifier.
1 parent 3685608 commit 8dc78be

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/glow/Optimizer/IROptimizer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,15 @@ static void shareBuffers(Module &M) {
221221
liveBuffers.insert(W);
222222
}
223223

224+
// Output buffers of the current instruction.
225+
std::unordered_set<Value *> outBuffers;
226+
224227
// For each instruction, in reverse order.
225228
for (auto it = instrs.rbegin(), e = instrs.rend(); it != e; ++it) {
226229
Instruction *I = *it;
227230

231+
outBuffers.clear();
232+
228233
// Remove <out> dependencies from the live set, because this instruction
229234
// writes into them. This means that the buffer is unused before the write
230235
// point.
@@ -241,6 +246,7 @@ static void shareBuffers(Module &M) {
241246
auto it = liveBuffers.find(ai);
242247
if (it != liveBuffers.end()) {
243248
liveBuffers.erase(it);
249+
outBuffers.insert(ai);
244250
}
245251
continue;
246252
}
@@ -249,6 +255,12 @@ static void shareBuffers(Module &M) {
249255
if (ai && O.second == OperandKind::InOut) {
250256
liveBuffers.insert(ai);
251257
}
258+
// The <In> use of a buffer that is also used as an <Out> means that the
259+
// value of the buffer is being consumed, which means that it is alive.
260+
// Add to the live set.
261+
if (ai && O.second == OperandKind::In && outBuffers.count(ai) > 0) {
262+
liveBuffers.insert(ai);
263+
}
252264
}
253265

254266
// Now that we've calculated the liveness for the exact location of the

0 commit comments

Comments
 (0)