commit 2482f4dbbb8a8fdc1a1bc398d5b8ca6f5af1fbd6
parent e5983ba1a2174fe7fd004692a427aae5bfc0dc4c
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Thu, 6 Aug 2015 13:08:31 -0400
fix two bugs in isel
Diffstat:
5 files changed, 11 insertions(+), 6 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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