diff options
author | Michael Forney <mforney@mforney.org> | 2021-04-07 16:48:22 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2021-04-08 00:48:42 -0700 |
commit | 6b5d015ee3ad1fe46e3238b7505dd6e0047a8f7b (patch) | |
tree | 75b3ede2429168897d06cffee9fc78200331a91e | |
parent | 1c9fdf33eb2d4179c2c705dae0a13a00c2227af3 (diff) |
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.
-rw-r--r-- | qbe.c | 35 |
1 files changed, 7 insertions, 28 deletions
@@ -451,19 +451,6 @@ ftou(struct func *f, struct repr *r, struct value *v) } 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) { enum instkind op; @@ -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 |