Skip to content

Fix a bug in shareBuffers #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/glow/Optimizer/IROptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,15 @@ static void shareBuffers(Module &M) {
liveBuffers.insert(W);
}

// Output buffers of the current instruction.
std::unordered_set<Value *> outBuffers;

// For each instruction, in reverse order.
for (auto it = instrs.rbegin(), e = instrs.rend(); it != e; ++it) {
Instruction *I = *it;

outBuffers.clear();

// Remove <out> dependencies from the live set, because this instruction
// writes into them. This means that the buffer is unused before the write
// point.
Expand All @@ -241,6 +246,7 @@ static void shareBuffers(Module &M) {
auto it = liveBuffers.find(ai);
if (it != liveBuffers.end()) {
liveBuffers.erase(it);
outBuffers.insert(ai);
}
continue;
}
Expand All @@ -249,6 +255,12 @@ static void shareBuffers(Module &M) {
if (ai && O.second == OperandKind::InOut) {
liveBuffers.insert(ai);
}
// The <In> use of a buffer that is also used as an <Out> means that the
// value of the buffer is being consumed, which means that it is alive.
// Add to the live set.
if (ai && O.second == OperandKind::In && outBuffers.count(ai) > 0) {
liveBuffers.insert(ai);
}
}

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