cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 0741a9b99ee72481e11272081343cc655a3a856f
parent 6400c868e2b320cac821581ed4bc6a65e2a216fc
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 27 Jun 2019 16:10:44 -0700

qbe: Fix switch statements with 64-bit controlling expression

Diffstat:
Mqbe.c | 6+++---
Atest/switch-long-long.c | 7+++++++
Atest/switch-long-long.qbe | 30++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/qbe.c b/qbe.c @@ -995,11 +995,11 @@ casesearch(struct func *f, struct value *v, struct switchcase *c, struct value * label[2] = mkblock("switch_gt"); // XXX: linear search if c->node.height < 4 - key = mkintconst(&i64, c->node.key); - res = funcinst(f, ICEQW, &i32, v, key); + key = mkintconst(v->repr, c->node.key); + res = funcinst(f, v->repr->base == 'w' ? ICEQW : ICEQL, &i32, v, key); funcjnz(f, res, c->body, label[0]); funclabel(f, label[0]); - res = funcinst(f, ICULTW, typeint.repr, v, key); + res = funcinst(f, v->repr->base == 'w' ? ICULTW : ICULTL, &i32, v, key); funcjnz(f, res, label[1], label[2]); funclabel(f, label[1]); casesearch(f, v, c->node.child[0], defaultlabel); diff --git a/test/switch-long-long.c b/test/switch-long-long.c @@ -0,0 +1,7 @@ +int main(void) { + switch (0x12300000000) { + case 0: return 1; + case 0x12300000000: return 0; + } + return 2; +} diff --git a/test/switch-long-long.qbe b/test/switch-long-long.qbe @@ -0,0 +1,30 @@ +export +function w $main() { +@start.1 +@body.2 + jmp @switch_cond.3 +@switch_case.5 + ret 1 +@switch_case.6 + ret 0 +@switch_cond.3 + %.1 =w ceql 1249835483136, 0 + jnz %.1, @switch_case.5, @switch_ne.7 +@switch_ne.7 + %.2 =w cultl 1249835483136, 0 + jnz %.2, @switch_lt.8, @switch_gt.9 +@switch_lt.8 + jmp @switch_join.4 +@switch_gt.9 + %.3 =w ceql 1249835483136, 1249835483136 + jnz %.3, @switch_case.6, @switch_ne.10 +@switch_ne.10 + %.4 =w cultl 1249835483136, 1249835483136 + jnz %.4, @switch_lt.11, @switch_gt.12 +@switch_lt.11 + jmp @switch_join.4 +@switch_gt.12 + jmp @switch_join.4 +@switch_join.4 + ret 2 +}