qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit 7815610cd8af498beac01d3ae6a1c9b20f1f0a8d
parent ea4b47003b1b2bb0ec204e90e3a3f1b0bb0a6090
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date:   Thu, 29 Dec 2016 17:51:26 -0500

simplify seladdr()

This also provides a violent fix to a bug causing an invalid
addressing to be generated when indexing into a global variable.
The fix is not satisfactory, though, as bad code is generated
(instead of invalid code before).

Diffstat:
Misel.c | 28+++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/isel.c b/isel.c @@ -24,7 +24,6 @@ typedef struct ANum ANum; struct ANum { char n, l, r; Ins *i; - Ref mem; }; static void amatch(Addr *, Ref, ANum *, Fn *, int); @@ -158,24 +157,19 @@ static void seladdr(Ref *r, ANum *an, Fn *fn) { Addr a; - Ref r0, r1; + Ref r0; r0 = *r; if (rtype(r0) == RTmp) { + amatch(&a, r0, an, fn, 1); + if (req(a.base, R)) + return; chuse(r0, -1, fn); - r1 = an[r0.val].mem; - if (req(r1, R)) { - amatch(&a, r0, an, fn, 1); - vgrow(&fn->mem, ++fn->nmem); - fn->mem[fn->nmem-1] = a; - r1 = MEM(fn->nmem-1); - chuse(a.base, +1, fn); - chuse(a.index, +1, fn); - if (rtype(a.base) != RTmp) - if (rtype(a.index) != RTmp) - an[r0.val].mem = r1; - } - *r = r1; + vgrow(&fn->mem, ++fn->nmem); + fn->mem[fn->nmem-1] = a; + chuse(a.base, +1, fn); + chuse(a.index, +1, fn); + *r = MEM(fn->nmem-1); } } @@ -629,5 +623,9 @@ isel(Fn *fn) if (debug['I']) { fprintf(stderr, "\n> After instruction selection:\n"); printfn(fn, stderr); + for (n=0; n<fn->ntmp; ++n) { + if (strcmp(fn->tmp[n].name, "i") == 0) + fprintf(stderr, ">> nuse for i: %d\n", fn->tmp[n].nuse); + } } }