ref: 9b5f3a1e365c76c67ed6f73499b461ace3c8f369
parent: 49a846b16c0187b5f59fc7bb7c336b919f5342ac
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jun 14 10:17:16 EDT 2014
Take into account subregisters when coalescing.
This fixes a bug we may potentially hit in register allocation
when we have a different size register we want to coalesce. Eg:
movb %P.117,%P.118
xorl %rax,%rax
movb %P.118,%al
This change prevents coalescing %al with a clobbered register.
--- a/6/ra.c
+++ b/6/ra.c
@@ -763,6 +763,18 @@
}
}
+static int constrained(Isel *s, regid u, regid v)
+{+ size_t i;
+
+ if (bshas(s->prepainted, v))
+ return 1;
+ if (bshas(s->prepainted, u))
+ for (i = 0; i < Nmode; i++)
+ if (regmap[colourmap[u]][i] && gbhasedge(s, regmap[colourmap[u]][i], v))
+ return 1;
+ return gbhasedge(s, u, v);
+}
static void coalesce(Isel *s)
{Insn *m;
@@ -782,7 +794,7 @@
lappend(&s->mcoalesced, &s->nmcoalesced, m);
wladd(s, u);
wladd(s, v);
- } else if (bshas(s->prepainted, v) || gbhasedge(s, u, v)) {+ } else if (constrained(s, u, v)) {lappend(&s->mconstrained, &s->nmconstrained, m);
wladd(s, u);
wladd(s, v);
@@ -879,7 +891,7 @@
}
/*
- * Selects the colors for registers, spilling to the
+ * Selects the colours for registers, spilling to the
* stack if no free registers can be found.
*/
static int paint(Isel *s)
--
⑨