From a60cff4d39926461eaa9ec777f793083b44cc690 Mon Sep 17 00:00:00 2001
From: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Tue, 15 Sep 2015 01:09:55 -0400
Subject: [PATCH] fix call bug in rega

When rdx is used to return a value and is used as argument,
it is in the call defs and hence made dead by the loop
modified here.  This is obviously erroneous behavior.
We instead rephrase the loop to make it clear that among
the caller-save registers, only the ones used by the call
must be live before the call.
---
 lisc/rega.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisc/rega.c b/lisc/rega.c
index 1263c6a..e792d55 100644
--- a/lisc/rega.c
+++ b/lisc/rega.c
@@ -320,10 +320,10 @@ rega(Fn *fn)
 		for (i=&b->ins[b->nins]; i!=b->ins;) {
 			switch ((--i)->op) {
 			case OCall:
-				rs = calldef(*i, 0) | callclb(*i, 0);
-				for (r=0; r<NReg; r++)
-					if ((1ll << r) & rs)
-						rfree(&cur, r);
+				rs = calluse(*i, 0);
+				for (r=0; r<NRSave; r++)
+					if (!((1ll << rsave[r]) & rs))
+						rfree(&cur, rsave[r]);
 				continue;
 			case OCopy:
 				if (!isreg(i->arg[0]))