From 4a809d69b5647aabc8f6a9e22e0bc889f9c779ed Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Thu, 11 Apr 2024 10:28:41 +0200 Subject: fold scaled offsets in addresses --- amd64/emit.c | 2 +- amd64/isel.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'amd64') diff --git a/amd64/emit.c b/amd64/emit.c index 51d1a5c..9636209 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -293,7 +293,7 @@ Next: if (rtype(m->base) == RSlot) { off.type = CBits; off.bits.i = slot(m->base, fn); - addcon(&m->offset, &off); + addcon(&m->offset, &off, 1); m->base = TMP(RBP); } if (m->offset.type != CUndef) diff --git a/amd64/isel.c b/amd64/isel.c index 5f14ba3..ed0ba66 100644 --- a/amd64/isel.c +++ b/amd64/isel.c @@ -692,7 +692,7 @@ anumber(Num *tn, Blk *b, Con *con) } static Ref -adisp(Con *c, Num *tn, Ref r, Fn *fn) +adisp(Con *c, Num *tn, Ref r, Fn *fn, int s) { Ref v[2]; int n; @@ -704,7 +704,7 @@ adisp(Con *c, Num *tn, Ref r, Fn *fn) break; runmatch(matcher[Pob], tn, r, v); assert(rtype(v[0]) == RCon); - addcon(c, &fn->con[v[0].val]); + addcon(c, &fn->con[v[0].val], s); r = v[1]; } return r; @@ -733,18 +733,18 @@ amatch(Addr *a, Num *tn, Ref r, Fn *fn) memset(&co, 0, sizeof co); ro = v[0]; - rb = adisp(&co, tn, v[1], fn); + rb = adisp(&co, tn, v[1], fn, 1); ri = v[2]; rs = v[3]; s = 1; if (*p < 0 && co.type != CUndef) if (amatch(a, tn, rb, fn)) - return addcon(&a->offset, &co); + return addcon(&a->offset, &co, 1); if (!req(ro, R)) { assert(rtype(ro) == RCon); c = &fn->con[ro.val]; - if (!addcon(&co, c)) + if (!addcon(&co, c, 1)) return 0; } if (!req(rs, R)) { @@ -753,6 +753,7 @@ amatch(Addr *a, Num *tn, Ref r, Fn *fn) assert(c->type = CBits); s = c->bits.i; } + ri = adisp(&co, tn, ri, fn, s); *a = (Addr){co, rb, ri, s}; if (rtype(ri) == RTmp) -- cgit v1.2.3