summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-21 16:06:06 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:32 -0400
commit681a4c8e3b1b9912ae9560e7016565da1fe54ab2 (patch)
treea95029e76eeed7826c44493c86cb363123d12dff /lisc
parent60b8b06aaba3cf63da32a2894b5a70a77596399f (diff)
downloadroux-681a4c8e3b1b9912ae9560e7016565da1fe54ab2.tar.gz
update dopm()
I could never figure out a correct version
without the tests.  I'm now fairly confident
dopm() will work as we need it to.
Diffstat (limited to 'lisc')
-rw-r--r--lisc/rega.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/lisc/rega.c b/lisc/rega.c
index 6340565..1e69d41 100644
--- a/lisc/rega.c
+++ b/lisc/rega.c
@@ -219,50 +219,38 @@ dopm(Blk *b, Ins *i, RMap *m)
 	i1 = i+1;
 	for (;; i--) {
 		r = RBASE(i->arg[0].val);
-		r1 = req(i->to, R) ? -1 : rfind(m, i->to.val);
-		if (!BGET(m->b, r)) {
-			/* r is not used by anybody,
-			 * i->to could have no register */
-			if (r1 != -1)
-				rfree(m, i->to.val);
-			radd(m, i->to.val, r);
-		} else if (r1 != r) {
-			/* r is used and not by i->to,
-			 * i->to could have no register */
+		r1 = req(i->to, R) ? -1 : rfree(m, i->to.val);
+		if (BGET(m->b, r) && r1 != r) {
+			/* r is used and not by i->to, */
 			for (n=0; m->r[n] != r; n++)
 				assert(n+1 < m->n);
 			t = m->t[n];
 			rfree(m, t);
-			if (m->n == NReg-1) {
-				/* swap the two locations */
-				assert(r1 != -1);
-				rfree(m, i->to.val);
-				radd(m, i->to.val, r);
-				radd(m, t, r1);
-			} else {
-				BSET(m->b, r);
-				ralloc(m, t);
-				BCLR(m->b, r);
-			}
-		} /* else r is already allocated for i->to */
+			BSET(m->b, r);
+			ralloc(m, t);
+			BCLR(m->b, r);
+		}
+		t = r1 == -1 ? r : i->to.val;
+		radd(m, t, r);
 		if (i == b->ins
 		|| (i-1)->op != OCopy
 		|| !isreg((i-1)->arg[0]))
 			break;
 	}
 	assert(m0.n <= m->n);
-	for (npm=0, n=0; n<m->n; n++) {
-		t = m->t[n];
-		r1 = m->r[n];
-		r = rfind(&m0, t);
-		if (r != r1)
+	for (npm=0, n=0; n<m->n; n++)
+		if ((t = m->t[n]) >= Tmp0) {
+			r1 = m->r[n];
+			r = rfind(&m0, t);
+			assert(r != -1);
 			pmadd(reg(r1, t), reg(r, t));
-	}
+		}
 	for (ip=i; ip<i1; ip++) {
 		if (!req(ip->to, R))
 			rfree(m, ip->to.val);
 		r = RBASE(ip->arg[0].val);
-		radd(m, r, r);
+		if (rfind(m, r) == -1)
+			radd(m, r, r);
 	}
 	pmgen();
 #ifdef TEST_PMOV