aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
+}