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

Rewrite IREquality to use a more compact stack instead of deep recursion #8198

Merged
merged 6 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/Associativity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool associative_op_pattern_match(const Expr &e,
debug(5) << "Adding result: " << iter.first << " -> " << iter.second << "\n";
match.emplace(iter.first, iter.second);
} else {
if (!equal(iter.first, match_iter->first) || !equal(iter.second, match_iter->second)) {
if (iter.first != match_iter->first || !equal(iter.second, match_iter->second)) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ int static_sign(const Expr &x) {
return -1;
} else {
Expr zero = make_zero(x.type());
if (equal(const_true(), simplify(x > zero))) {
if (is_const_one(simplify(x > zero))) {
return 1;
} else if (equal(const_true(), simplify(x < zero))) {
} else if (is_const_one(simplify(x < zero))) {
return -1;
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/CSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,23 @@ class GVN : public IRMutator {
Expr expr;
int use_count = 0;
// All consumer Exprs for which this is the last child Expr.
map<ExprWithCompareCache, int> uses;
map<Expr, int, IRGraphDeepCompare> uses;
Entry(const Expr &e)
: expr(e) {
}
};
vector<std::unique_ptr<Entry>> entries;

map<Expr, int, ExprCompare> shallow_numbering, output_numbering;
map<ExprWithCompareCache, int> leaves;
map<Expr, int, IRGraphDeepCompare> leaves;

int number = -1;

IRCompareCache cache;

GVN()
: number(0), cache(8) {
}
int number = 0;

Stmt mutate(const Stmt &s) override {
internal_error << "Can't call GVN on a Stmt: " << s << "\n";
return Stmt();
}

ExprWithCompareCache with_cache(const Expr &e) {
return ExprWithCompareCache(e, &cache);
}

Expr mutate(const Expr &e) override {
// Early out if we've already seen this exact Expr.
{
Expand All @@ -123,7 +113,7 @@ class GVN : public IRMutator {
// that child has an identical parent to this one.

auto &use_map = number == -1 ? leaves : entries[number]->uses;
auto p = use_map.emplace(with_cache(new_e), (int)entries.size());
auto p = use_map.emplace(new_e, (int)entries.size());
auto iter = p.first;
bool novel = p.second;
if (novel) {
Expand Down
Loading
Loading