diff --git a/amd64/emit.c b/amd64/emit.c index 4a3bb99..d1efc49 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -710,7 +710,7 @@ amd64_sysv_emitfn(Fn *fn, FILE *f) default: c = b->jmp.type - Jjf; if (0 <= c && c <= NCmp) { - if (b->link == b->s2) { + if (b->link == b->s2 || c >= NCmpI) { s = b->s1; b->s1 = b->s2; b->s2 = s; @@ -827,7 +827,7 @@ amd64_winabi_emitfn(Fn *fn, FILE *f) default: c = b->jmp.type - Jjf; if (0 <= c && c <= NCmp) { - if (b->link == b->s2) { + if (b->link == b->s2 || c >= NCmpI) { s = b->s1; b->s1 = b->s2; b->s2 = s; diff --git a/util.c b/util.c index c891c4e..a5fa790 100644 --- a/util.c +++ b/util.c @@ -343,31 +343,31 @@ icpy(Ins *d, Ins *s, ulong n) } static int cmptab[][2] ={ - /* negation swap */ - [Ciule] = {Ciugt, Ciuge}, - [Ciult] = {Ciuge, Ciugt}, - [Ciugt] = {Ciule, Ciult}, - [Ciuge] = {Ciult, Ciule}, - [Cisle] = {Cisgt, Cisge}, - [Cislt] = {Cisge, Cisgt}, - [Cisgt] = {Cisle, Cislt}, - [Cisge] = {Cislt, Cisle}, - [Cieq] = {Cine, Cieq}, - [Cine] = {Cieq, Cine}, - [NCmpI+Cfle] = {NCmpI+Cfgt, NCmpI+Cfge}, - [NCmpI+Cflt] = {NCmpI+Cfge, NCmpI+Cfgt}, - [NCmpI+Cfgt] = {NCmpI+Cfle, NCmpI+Cflt}, - [NCmpI+Cfge] = {NCmpI+Cflt, NCmpI+Cfle}, - [NCmpI+Cfeq] = {NCmpI+Cfne, NCmpI+Cfeq}, - [NCmpI+Cfne] = {NCmpI+Cfeq, NCmpI+Cfne}, - [NCmpI+Cfo] = {NCmpI+Cfuo, NCmpI+Cfo}, - [NCmpI+Cfuo] = {NCmpI+Cfo, NCmpI+Cfuo}, + /* negation swap */ + [Ciule] = {Ciugt, Ciuge}, + [Ciult] = {Ciuge, Ciugt}, + [Ciugt] = {Ciule, Ciult}, + [Ciuge] = {Ciult, Ciule}, + [Cisle] = {Cisgt, Cisge}, + [Cislt] = {Cisge, Cisgt}, + [Cisgt] = {Cisle, Cislt}, + [Cisge] = {Cislt, Cisle}, + [Cieq] = {Cine, Cieq}, + [Cine] = {Cieq, Cine}, + [NCmpI+Cfle] = {-1, NCmpI+Cfge}, + [NCmpI+Cflt] = {-1, NCmpI+Cfgt}, + [NCmpI+Cfgt] = {-1, NCmpI+Cflt}, + [NCmpI+Cfge] = {-1, NCmpI+Cfle}, + [NCmpI+Cfeq] = {-1, NCmpI+Cfeq}, + [NCmpI+Cfne] = {-1, NCmpI+Cfne}, + [NCmpI+Cfo] = {-1, NCmpI+Cfo}, + [NCmpI+Cfuo] = {-1, NCmpI+Cfuo}, }; int cmpneg(int c) { - assert(0 <= c && c < NCmp); + assert(0 <= c && c < NCmpI); return cmptab[c][0]; }