aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-06-27 16:10:44 -0700
committerMichael Forney <mforney@mforney.org>2019-06-27 16:36:51 -0700
commit0741a9b99ee72481e11272081343cc655a3a856f (patch)
tree1222919710d878458f6ba26c4d4c8bc4966aa649
parent6400c868e2b320cac821581ed4bc6a65e2a216fc (diff)
qbe: Fix switch statements with 64-bit controlling expression
-rw-r--r--qbe.c6
-rw-r--r--test/switch-long-long.c7
-rw-r--r--test/switch-long-long.qbe30
3 files changed, 40 insertions, 3 deletions
diff --git a/qbe.c b/qbe.c
index 7c63c39..33f6921 100644
--- 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
new file mode 100644
index 0000000..65e022f
--- /dev/null
+++ 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
new file mode 100644
index 0000000..a13feab
--- /dev/null
+++ 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
+}