summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-04-12 14:06:18 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-04-12 14:51:50 -0400
commit861bb7c53421097091fc53c9ce5d0de1420b908d (patch)
tree23868465221b947a082618e10fda1ab9e806e7d4
parentff53f2258da52d2f35c4cb38b9e31406d48264c3 (diff)
downloadroux-861bb7c53421097091fc53c9ce5d0de1420b908d.tar.gz
the lattice merge has to be used in update()
-rw-r--r--fold.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/fold.c b/fold.c
index 253c52e..6d62841 100644
--- a/fold.c
+++ b/fold.c
@@ -42,19 +42,26 @@ latval(Ref r)
 	}
 }
 
+static int
+latmerge(int v, int m)
+{
+	return m == Top ? v : (v == Top || (v != Bot && m != Bot && v == m)) ? m : Bot;
+}
+
 static void
-update(int t, int v, Fn *fn)
+update(int t, int m, Fn *fn)
 {
 	Tmp *tmp;
 	uint u;
 
-	if (val[t] != v) {
+	m = latmerge(val[t], m);
+	if (m != val[t]) {
 		tmp = &fn->tmp[t];
 		for (u=0; u<tmp->nuse; u++) {
 			vgrow(&usewrk, ++nuse);
 			usewrk[nuse-1] = &tmp->use[u];
 		}
-		val[t] = v;
+		val[t] = m;
 	}
 }
 
@@ -74,12 +81,8 @@ visitphi(Phi *p, int n, Fn *fn)
 		else
 			die("invalid phi argument");
 		m = latval(p->arg[a]);
-		if (!dead && m != Top) {
-			if (v != Top && (v == Bot || m == Bot || v != m))
-				v = Bot;
-			else
-				v = m;
-		}
+		if (!dead)
+			v = latmerge(v, m);
 	}
 	update(p->to.val, v, fn);
 }
@@ -119,6 +122,7 @@ visitjmp(Blk *b, int n, Fn *fn)
 	switch (b->jmp.type) {
 	case JJnz:
 		l = latval(b->jmp.arg);
+		assert(l != Top);
 		if (l == Bot) {
 			edge[n][1].work = flowrk;
 			edge[n][0].work = &edge[n][1];