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 abccebea439d961c39e4a6f7d54f72e0b24e9100
parent 13fb267e24dd0fbe011d29dc6d3b2512c66118b6
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 13 Feb 2019 12:26:14 -0800

Compare to node value first when looking for switch destination

Diffstat:
Mqbe.c | 14+++++++-------
Mtests/switch.qbe | 60++++++++++++++++++++++++++++++------------------------------
2 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/qbe.c b/qbe.c @@ -852,19 +852,19 @@ casesearch(struct function *f, struct value *v, struct switchcase *c, struct val funcjmp(f, defaultlabel); return; } - label[0] = mkblock("switch_lt"); - label[1] = mkblock("switch_ge"); + label[0] = mkblock("switch_ne"); + label[1] = mkblock("switch_lt"); label[2] = mkblock("switch_gt"); // XXX: linear search if c->node.height < 4 key = mkintconst(&i64, c->node.key); - res = funcinst(f, ICULTW, &i32, (struct value *[]){v, key}); - funcjnz(f, res, label[0], label[1]); + res = funcinst(f, ICEQW, &i32, (struct value *[]){v, key}); + funcjnz(f, res, c->body, label[0]); funclabel(f, label[0]); - casesearch(f, v, c->node.child[0], defaultlabel); + res = funcinst(f, ICULTW, typeint.repr, (struct value *[]){v, key}); + funcjnz(f, res, label[1], label[2]); funclabel(f, label[1]); - res = funcinst(f, ICUGTW, typeint.repr, (struct value *[]){v, key}); - funcjnz(f, res, label[2], c->body); + casesearch(f, v, c->node.child[0], defaultlabel); funclabel(f, label[2]); casesearch(f, v, c->node.child[1], defaultlabel); } diff --git a/tests/switch.qbe b/tests/switch.qbe @@ -16,45 +16,45 @@ function $f() { @switch_case.10 jmp @switch_join.4 @switch_cond.3 - %.1 =w cultw 0, 52 - jnz %.1, @switch_lt.11, @switch_ge.12 -@switch_lt.11 - %.2 =w cultw 0, 3 - jnz %.2, @switch_lt.14, @switch_ge.15 -@switch_lt.14 - %.3 =w cultw 0, 0 - jnz %.3, @switch_lt.17, @switch_ge.18 -@switch_lt.17 + %.1 =w ceqw 0, 52 + jnz %.1, @switch_case.6, @switch_ne.11 +@switch_ne.11 + %.2 =w cultw 0, 52 + jnz %.2, @switch_lt.12, @switch_gt.13 +@switch_lt.12 + %.3 =w ceqw 0, 3 + jnz %.3, @switch_case.5, @switch_ne.14 +@switch_ne.14 + %.4 =w cultw 0, 3 + jnz %.4, @switch_lt.15, @switch_gt.16 +@switch_lt.15 + %.5 =w ceqw 0, 0 + jnz %.5, @switch_case.9, @switch_ne.17 +@switch_ne.17 + %.6 =w cultw 0, 0 + jnz %.6, @switch_lt.18, @switch_gt.19 +@switch_lt.18 jmp @switch_default.8 -@switch_ge.18 - %.4 =w cugtw 0, 0 - jnz %.4, @switch_gt.19, @switch_case.9 @switch_gt.19 jmp @switch_default.8 -@switch_ge.15 - %.5 =w cugtw 0, 3 - jnz %.5, @switch_gt.16, @switch_case.5 @switch_gt.16 jmp @switch_default.8 -@switch_ge.12 - %.6 =w cugtw 0, 52 - jnz %.6, @switch_gt.13, @switch_case.6 @switch_gt.13 - %.7 =w cultw 0, 18446744073709551613 - jnz %.7, @switch_lt.20, @switch_ge.21 -@switch_lt.20 - %.8 =w cultw 0, 101 - jnz %.8, @switch_lt.23, @switch_ge.24 -@switch_lt.23 + %.7 =w ceqw 0, 18446744073709551613 + jnz %.7, @switch_case.7, @switch_ne.20 +@switch_ne.20 + %.8 =w cultw 0, 18446744073709551613 + jnz %.8, @switch_lt.21, @switch_gt.22 +@switch_lt.21 + %.9 =w ceqw 0, 101 + jnz %.9, @switch_case.10, @switch_ne.23 +@switch_ne.23 + %.10 =w cultw 0, 101 + jnz %.10, @switch_lt.24, @switch_gt.25 +@switch_lt.24 jmp @switch_default.8 -@switch_ge.24 - %.9 =w cugtw 0, 101 - jnz %.9, @switch_gt.25, @switch_case.10 @switch_gt.25 jmp @switch_default.8 -@switch_ge.21 - %.10 =w cugtw 0, 18446744073709551613 - jnz %.10, @switch_gt.22, @switch_case.7 @switch_gt.22 jmp @switch_default.8 @switch_join.4