Skip to content
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

Stronger chain detection in LoopCarry pass #8016

Merged
merged 10 commits into from
Jan 9, 2024
9 changes: 7 additions & 2 deletions src/LoopCarry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,16 @@ class LoopCarryOverLoop : public IRMutator {
if (i == j) {
continue;
}
// can_prove is stronger than graph_equal, because it doesn't require index expressions to be
// exactly the same, but evalutate to the same value. We keep the graph_equal check, because
vksnk marked this conversation as resolved.
Show resolved Hide resolved
// it's faster and should be executed before the more expensive check.
if (loads[i][0]->name == loads[j][0]->name &&
next_indices[j].defined() &&
graph_equal(indices[i], next_indices[j]) &&
(graph_equal(indices[i], next_indices[j]) ||
((indices[i].type() == next_indices[j].type()) && can_prove(indices[i] == next_indices[j]))) &&
next_predicates[j].defined() &&
graph_equal(predicates[i], next_predicates[j])) {
(graph_equal(predicates[i], next_predicates[j]) ||
((predicates[i].type() == next_predicates[j].type()) && can_prove(predicates[i] == next_predicates[j])))) {
chains.push_back({j, i});
debug(3) << "Found carried value:\n"
<< i << ": -> " << Expr(loads[i][0]) << "\n"
Expand Down