fix crash on loop analyzer
add assert for previously unstated assumption
MODIFY
ir/fast_math.cpp
ir/fast_math.cpp
@@ -80,7 +80,7 @@ class EGraph {
void decl_equivalent(Node &&node, unsigned n1) {
unsigned n2 = get(move(node));
- unsigned new_root = uf.merge(n1, n2);
+ unsigned new_root = uf.merge(n2, n1);
auto &root = nodes_eqs[new_root];
auto merge = [&](unsigned n) {

MODIFY
ir/function.cpp
ir/function.cpp
@@ -1037,7 +1037,7 @@ void LoopAnalysis::run() {
for (unsigned x : P) {
header[x] = w;
- uf.merge(x, w);
+ ENSURE(uf.merge(x, w) == w);
}
}

MODIFY
util/unionfind.cpp
util/unionfind.cpp
@@ -30,8 +30,8 @@ unsigned UnionFind::find(unsigned i) {
unsigned UnionFind::merge(unsigned p, unsigned q) {
unsigned i = find(p);
unsigned j = find(q);
- id[j] = i;
- return i;
+ id[i] = j;
+ return j;
}
}

fix crash on loop analyzer
add assert for previously unstated assumption