From 2482f4dbbb8a8fdc1a1bc398d5b8ca6f5af1fbd6 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Thu, 6 Aug 2015 13:08:31 -0400 Subject: fix two bugs in isel --- lisc/emit.c | 2 ++ lisc/isel.c | 5 +++-- lisc/lisc.h | 4 +++- lisc/parse.c | 2 +- lisc/test/cup.ssa | 4 ++-- 5 files changed, 11 insertions(+), 6 deletions(-) (limited to 'lisc') 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 -- cgit 1.4.1