summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--rega.c8
-rw-r--r--test/rega1.ssa24
2 files changed, 29 insertions, 3 deletions
diff --git a/rega.c b/rega.c
index f087f3c..9ceba70 100644
--- a/rega.c
+++ b/rega.c
@@ -571,7 +571,8 @@ rega(Fn *fn)
 				if (rtype(src) != RTmp)
 					continue;
 				x = rfind(&end[b->id], src.val);
-				assert(x != -1);
+				if (x == -1) /* spilled */
+					continue;
 				rl[r] = (!rl[r] || rl[r] == x) ? x : -1;
 			}
 			if (rl[r] == 0)
@@ -586,7 +587,8 @@ rega(Fn *fn)
 				continue;
 			for (bp=s->pred; bp<&s->pred[s->npred]; bp++) {
 				x = rfind(&end[(*bp)->id], t);
-				assert(x != -1);
+				if (x == -1) /* spilled */
+					continue;
 				rl[r] = (!rl[r] || rl[r] == x) ? x : -1;
 			}
 		}
@@ -597,7 +599,7 @@ rega(Fn *fn)
 			r = m->r[j];
 			x = rl[r];
 			assert(x != 0 || t < Tmp0 /* todo, ditto */);
-			if (x > 0) {
+			if (x > 0 && !bshas(m->b, x)) {
 				pmadd(TMP(x), TMP(r), tmp[t].cls);
 				m->r[j] = x;
 			}
diff --git a/test/rega1.ssa b/test/rega1.ssa
new file mode 100644
index 0000000..9e87c89
--- /dev/null
+++ b/test/rega1.ssa
@@ -0,0 +1,24 @@
+# tests that %b and %a0 do not end up in
+# the same register at the start of @loop
+
+export function l $f(l %a) {
+@start
+@loop
+	%b =l phi @start 42, @loop0 %a1, @loop1 %a1
+	%a0 =l phi @start %a, @loop0 %a1, @loop1 %a1
+	%a1 =l sub %a0, 1
+	jnz %b, @loop0, @loop1
+@loop0
+	jnz %a1, @loop, @end
+@loop1
+	jnz %a1, @loop, @end
+@end
+	ret %b
+}
+
+# >>> driver
+# extern long long f(long long);
+# int main() {
+# 	return !(f(1) == 42 && f(2) == 1 && f(42) == 1);
+# }
+# <<<