From 6b5d015ee3ad1fe46e3238b7505dd6e0047a8f7b Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 7 Apr 2021 16:48:22 -0700 Subject: qbe: Remove unnecessary extension for relational operands The operands are already promoted, so never need to be extended. These extend()s were added in 7d746860 in an attempt to fix a bug related to the comparison of values with type smaller than int. However, the real bug was that the operands should have been promoted to int by usual arithmetic conversions, which was fixed later in a8131372. --- qbe.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/qbe.c b/qbe.c index f3a6f44..2fdcc9c 100644 --- a/qbe.c +++ b/qbe.c @@ -450,19 +450,6 @@ ftou(struct func *f, struct repr *r, struct value *v) return &join->phi.res; } -static struct value * -extend(struct func *f, struct type *t, struct value *v) -{ - enum instkind op; - - switch (t->size) { - case 1: op = t->basic.issigned ? IEXTSB : IEXTUB; break; - case 2: op = t->basic.issigned ? IEXTSH : IEXTUH; break; - default: return v; - } - return funcinst(f, op, &i32, v, NULL); -} - static struct value * convert(struct func *f, struct type *dst, struct type *src, struct value *l) { @@ -478,12 +465,16 @@ convert(struct func *f, struct type *dst, struct type *src, struct value *l) if (!(src->prop & PROPREAL) || !(dst->prop & PROPREAL)) fatal("internal error; unsupported conversion"); if (dst->kind == TYPEBOOL) { - l = extend(f, src, l); r = mkintconst(src->repr, 0); - if (src->prop & PROPINT) + if (src->prop & PROPINT) { + switch (src->size) { + case 1: l = funcinst(f, IEXTUB, &i32, l, NULL); break; + case 2: l = funcinst(f, IEXTUH, &i32, l, NULL); break; + } op = src->size == 8 ? ICNEL : ICNEW; - else + } else { op = src->size == 8 ? ICNED : ICNES; + } } else if (dst->prop & PROPINT) { if (src->prop & PROPINT) { if (dst->size <= src->size) { @@ -823,48 +814,36 @@ funcexpr(struct func *f, struct expr *e) op = IXOR; break; case TLESS: - l = extend(f, t, l); - r = extend(f, t, r); if (t->size <= 4) op = t->prop & PROPFLOAT ? ICLTS : t->basic.issigned ? ICSLTW : ICULTW; else op = t->prop & PROPFLOAT ? ICLTD : t->basic.issigned ? ICSLTL : ICULTL; break; case TGREATER: - l = extend(f, t, l); - r = extend(f, t, r); if (t->size <= 4) op = t->prop & PROPFLOAT ? ICGTS : t->basic.issigned ? ICSGTW : ICUGTW; else op = t->prop & PROPFLOAT ? ICGTD : t->basic.issigned ? ICSGTL : ICUGTL; break; case TLEQ: - l = extend(f, t, l); - r = extend(f, t, r); if (t->size <= 4) op = t->prop & PROPFLOAT ? ICLES : t->basic.issigned ? ICSLEW : ICULEW; else op = t->prop & PROPFLOAT ? ICLED : t->basic.issigned ? ICSLEL : ICULEL; break; case TGEQ: - l = extend(f, t, l); - r = extend(f, t, r); if (t->size <= 4) op = t->prop & PROPFLOAT ? ICGES : t->basic.issigned ? ICSGEW : ICUGEW; else op = t->prop & PROPFLOAT ? ICGED : t->basic.issigned ? ICSGEL : ICUGEL; break; case TEQL: - l = extend(f, t, l); - r = extend(f, t, r); if (t->size <= 4) op = t->prop & PROPFLOAT ? ICEQS : ICEQW; else op = t->prop & PROPFLOAT ? ICEQD : ICEQL; break; case TNEQ: - l = extend(f, t, l); - r = extend(f, t, r); if (t->size <= 4) op = t->prop & PROPFLOAT ? ICNES : ICNEW; else -- cgit v1.2.3