summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-06 13:08:31 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:30 -0400
commit2482f4dbbb8a8fdc1a1bc398d5b8ca6f5af1fbd6 (patch)
tree623f29033d5fee4b948fa19de4013d6a20096cc2 /lisc
parente5983ba1a2174fe7fd004692a427aae5bfc0dc4c (diff)
downloadroux-2482f4dbbb8a8fdc1a1bc398d5b8ca6f5af1fbd6.tar.gz
fix two bugs in isel
Diffstat (limited to 'lisc')
-rw-r--r--lisc/emit.c2
-rw-r--r--lisc/isel.c5
-rw-r--r--lisc/lisc.h4
-rw-r--r--lisc/parse.c2
-rw-r--r--lisc/test/cup.ssa4
5 files changed, 11 insertions, 6 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index a1a70c4..665a418 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -68,7 +68,9 @@ static char *rbtoa[] = {
 static char *ctoa[NCmp] = {
 	[Ceq] = "e",
 	[Csle] = "le",
+	[Cslt] = "l",
 	[Csgt] = "g",
+	[Csge] = "ge",
 	[Cne] = "ne",
 };
 
diff --git a/lisc/isel.c b/lisc/isel.c
index ea4aa01..8fe7535 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -86,6 +86,7 @@ sel(Ins i, Fn *fn)
 		break;
 	default:
 		if (OCmp <= i.op && i.op <= OCmp1) {
+			t = -1;
 			r0 = i.arg[0];
 			c = i.op - OCmp;
 			if (rtype(i.arg[0]) == RCon) {
@@ -98,12 +99,12 @@ sel(Ins i, Fn *fn)
 				} else {
 					r0 = i.arg[1];
 					i.arg[1] = i.arg[0];
-					c = CNEG(c);
+					c = COP(c);
 				}
 			}
 			emit(OXSet+c, i.to, R, R);
 			emit(OXCmp, R, i.arg[1], r0);
-			if (!req(r0, i.arg[0]))
+			if (t != -1)
 				emit(OCopy, r0, i.arg[0], R);
 			break;
 		}
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 4e150db..2fe2614 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -108,12 +108,14 @@ static inline int rtype(Ref r)
 enum {
 	Ceq,
 	Csle,
+	Cslt,
 	Csgt, /* mirror opposite cmps! */
+	Csge,
 	Cne,
 	NCmp,
 };
 
-#define CNEG(c) (NCmp-1 - c)
+#define COP(c) (c==Ceq||c==Cne ? c : NCmp-1 - c)
 
 enum {
 	OXXX,
diff --git a/lisc/parse.c b/lisc/parse.c
index ae7cb8c..5969010 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -25,7 +25,7 @@ OpDesc opdesc[OLast] = {
 	[OXDiv]   = { "xdiv",  1, U },
 	[OXCmp]   = { "xcmp",  2, U },
 
-	#define I(X) X(eq), X(sle), X(sgt), X(ne)
+	#define I(X) X(eq), X(sle), X(slt), X(sgt), X(sge), X(ne)
 	#define CMP(c) [OCmp+C##c]  = { "c"    #c, 2, U }
 	#define SET(c) [OXSet+C##c] = { "xset" #c, 0, U }
 	I(CMP), I(SET)
diff --git a/lisc/test/cup.ssa b/lisc/test/cup.ssa
index 2626d26..4ffcf29 100644
--- a/lisc/test/cup.ssa
+++ b/lisc/test/cup.ssa
@@ -1,10 +1,10 @@
-# counts up
+# counts up from -1988 to 1991
 
 @start
 @loop
 	%n0  =w phi @start -1988, @loop %n1
 	%n1  =w add 1, %n0
-	%cmp =w csle 1990, %n1
+	%cmp =w csle 1991, %n1
 	jez %cmp, @loop, @end
 @end
 	ret