shithub: mc

Download patch

ref: f889abbd3860cfb5b26bcd791885f6aa149cb7e4
parent: c4030c7f8d157876db45c7becdf192065640e68d
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 2 21:49:49 EST 2016

Rewrite spills in reverse order.

--- a/6/ra.c
+++ b/6/ra.c
@@ -1155,8 +1155,8 @@
 	if (!bb)
 		return;
 	map = mkht(reglochash, regloceq);
-	for (j = 0; j < bb->ni; j++) {
-		insn = bb->il[j];
+	for (j = bb->ni; j > 0; j--) {
+		insn = bb->il[j - 1];
 		replacealias(s, aliasmap, s->nreg, insn);
 		if (nopmov(insn))
 			continue;
@@ -1164,26 +1164,26 @@
 		ndef = defs(insn, def);
 		/* if there is a remapping, insert the loads and stores as needed */
 		if (remap(s, map, insn, use, nuse, def, ndef)) {
-			for (i = 0; i < nuse; i++) {
-				tmp = htget(map, locmap[use[i]]);
+			for (i = 0; i < ndef; i++) {
+				tmp = htget(map, locmap[def[i]]);
 				if (!tmp)
 					continue;
 				if (isfloatmode(tmp->mode))
-					mov = mkinsn(Imovs, spillslot(s, use[i]), tmp, NULL);
+					mov = mkinsn(Imovs, tmp, spillslot(s, def[i]), NULL);
 				else
-					mov = mkinsn(Imov, spillslot(s, use[i]), tmp, NULL);
+					mov = mkinsn(Imov, tmp, spillslot(s, def[i]), NULL);
 				lappend(&new, &nnew, mov);
 			}
 			updatelocs(s, map, insn);
 			lappend(&new, &nnew, insn);
-			for (i = 0; i < ndef; i++) {
-				tmp = htget(map, locmap[def[i]]);
+			for (i = 0; i < nuse; i++) {
+				tmp = htget(map, locmap[use[i]]);
 				if (!tmp)
 					continue;
 				if (isfloatmode(tmp->mode))
-					mov = mkinsn(Imovs, tmp, spillslot(s, def[i]), NULL);
+					mov = mkinsn(Imovs, spillslot(s, use[i]), tmp, NULL);
 				else
-					mov = mkinsn(Imov, tmp, spillslot(s, def[i]), NULL);
+					mov = mkinsn(Imov, spillslot(s, use[i]), tmp, NULL);
 				lappend(&new, &nnew, mov);
 			}
 			for (i = 0; i < nuse; i++)
@@ -1193,6 +1193,11 @@
 		} else {
 			lappend(&new, &nnew, insn);
 		}
+	}
+	for (i = 0; i < nnew/2; i++) {
+		insn = new[i];
+		new[i] = new[nnew - i - 1];
+		new[nnew - i -1] = insn;
 	}
 	lfree(&bb->il, &bb->ni);
 	bb->il = new;