diff --git a/util/ego/cs/cs_profit.c b/util/ego/cs/cs_profit.c index 50cb708fd..8845aaa29 100644 --- a/util/ego/cs/cs_profit.c +++ b/util/ego/cs/cs_profit.c @@ -111,6 +111,21 @@ void cs_machinit(void *vp) choose_cset(f, &forbidden, sp_lmnem); } +bool may_become_aar(avail_p avp) +{ + /* Check whether it is desirable to treat a LAR or SAR as an + * AAR LOI/STI. This depends on the size of the array-elements. + */ + offset sz; + + sz = array_elemsize(avp->av_othird); + if (sz == UNKNOWN_SIZE) + return FALSE; + if (time_space_ratio < 50) + return sz <= AR_limit; + return TRUE; +} + STATIC bool sli_no_eliminate(line_p lnp) { /* Return whether the SLI-instruction in lnp is part of @@ -157,8 +172,10 @@ STATIC bool gains(avail_p avp) STATIC bool okay_lines(avail_p avp, occur_p ocp) { + /* Check whether all lines in this occurrence can in + * principle be eliminated; no stores, messages, calls etc. + */ register line_p lnp, next; - offset sz; for (lnp = ocp->oc_lfirst; lnp != (line_p) 0; lnp = next) { next = lnp != ocp->oc_llast ? lnp->l_next : (line_p) 0; @@ -171,18 +188,6 @@ STATIC bool okay_lines(avail_p avp, occur_p ocp) return FALSE; } } - /* All lines in this occurrence can in principle be eliminated; - * no stores, messages, calls etc. - * We now check whether it is desirable to treat a LAR or a SAR - * as an AAR LOI/STI. This depends on the size of the array-elements. - */ - if (INSTR(ocp->oc_llast) == op_lar || INSTR(ocp->oc_llast) == op_sar) { - sz = array_elemsize(avp->av_othird); - if (sz == UNKNOWN_SIZE) return FALSE; - if (avp->av_instr == (byte) op_aar && time_space_ratio < 50) { - return sz <= AR_limit; - } - } return TRUE; } diff --git a/util/ego/cs/cs_profit.h b/util/ego/cs/cs_profit.h index 7ec5e3c17..43f2bade9 100644 --- a/util/ego/cs/cs_profit.h +++ b/util/ego/cs/cs_profit.h @@ -7,6 +7,12 @@ void cs_machinit(void *vp); /* (FILE *f) * Read phase-specific information from f. */ +bool may_become_aar(avail_p avp); + /* + * Return whether a LAR/SAR may become + * an AAR LOI/STI. + */ + bool desirable(avail_p avp); /* * Return whether it is desirable to eliminate * the recurrences of the expression in avp. diff --git a/util/ego/cs/cs_vnm.c b/util/ego/cs/cs_vnm.c index 4dbeb3df2..67507f805 100644 --- a/util/ego/cs/cs_vnm.c +++ b/util/ego/cs/cs_vnm.c @@ -50,11 +50,13 @@ STATIC void put_expensive_load(bblock_p bp, line_p lnp, line_p lfirst, STATIC void put_aar(bblock_p bp, line_p lnp, line_p lfirst, entity_p enp) { - /* Enp points to an ENARRELEM. We do as if its address was computed. */ - + /* Enter the implicit AAR in a LAR or SAR, where enp points to + * the ENARRELEM, and AAR computes its address. + */ struct avail av; occur_p ocp; + assert(INSTR(lnp) == op_lar || INSTR(lnp) == op_sar); assert(enp->en_kind == ENARRELEM); av.av_instr = op_aar; av.av_size = ps; @@ -62,9 +64,14 @@ STATIC void put_aar(bblock_p bp, line_p lnp, line_p lfirst, entity_p enp) av.av_osecond = enp->en_index; av.av_othird = enp->en_adesc; - ocp = newoccur(lfirst, lnp, bp); - - av_enter(&av, ocp, TERNAIR_OP); + /* Before we enter an available AAR, we must check whether we + * may convert this LAR/SAR to AAR LOI/STI. This is so we + * don't LOI/STI a large or unknown size. + */ + if (may_become_aar(&av)) { + ocp = newoccur(lfirst, lnp, bp); + av_enter(&av, ocp, TERNAIR_OP); + } } STATIC void push_avail(avail_p avp, line_p lfirst)