From bf153b359e9ce3ebef9bca899eb7ed5bd9045c11 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 18 Nov 2021 01:45:27 -0800 Subject: reuse previous address constants in fold() parseref() has code to reuse address constants, but this is not done in other passes such as fold or isel. Introduce a new function newcon() which takes a Con and returns a Ref for that constant, and use this whenever creating address constants. This is necessary to fix folding of address constants when one operand is already folded. For example, in %a =l add $x, 1 %b =l add %a, 2 %c =w loadw %b %a and %b were folded to $x+1 and $x+3 respectively, but then the second add is visited again since it uses %a. This gets folded to $x+3 as well, but as a new distinct constant. This results in %b getting labeled as bottom instead of either constant, disabling the replacement of %b by a constant in subsequent instructions (such as the loadw). --- util.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 9a3576a..c8b0b9c 100644 --- a/util.c +++ b/util.c @@ -349,6 +349,25 @@ chuse(Ref r, int du, Fn *fn) fn->tmp[r.val].nuse += du; } +Ref +newcon(Con *c0, Fn *fn) +{ + Con *c1; + int i; + + for (i=0; incon; i++) { + c1 = &fn->con[i]; + if (c0->type == c1->type + && c0->bits.i == c1->bits.i + && c0->label == c1->label + && c0->local == c1->local) + return CON(i); + } + vgrow(&fn->con, ++fn->ncon); + fn->con[i] = *c0; + return CON(i); +} + Ref getcon(int64_t val, Fn *fn) { -- cgit 1.4.1