From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2119) id B36473858C78; Mon, 18 Sep 2023 18:26:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B36473858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695061600; bh=bUGZcxQyfESNqb841n3U8qj6FhCA1X+kzLFOmHJgmgU=; h=From:To:Subject:Date:From; b=Ao8O7jbcm2fQAh5Zpq/qXbZenODFLSuFX6YhghCt2I+lZyPRyb/PslZI9PFC3YGZx wODDoE/QxiC/NC6midRbBpacNveUNKKIib0yf/wdW5JoQrPWIRDkPvUI3ADVVMbu87 seO7c1TTCZVFZdN98+h/32qvFHjOjxi+CYwvodFw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jeff Law To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] [RA]: Improve cost calculation of pseudos with equivalences X-Act-Checkin: gcc X-Git-Author: Vladimir N. Makarov X-Git-Refname: refs/vendors/riscv/heads/gcc-13-with-riscv-opts X-Git-Oldrev: d99766a42d0a29bf12704cb55ff320d684032a6d X-Git-Newrev: 2c80f25679657032a65ecd3d18650167617a5679 Message-Id: <20230918182640.B36473858C78@sourceware.org> Date: Mon, 18 Sep 2023 18:26:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2c80f25679657032a65ecd3d18650167617a5679 commit 2c80f25679657032a65ecd3d18650167617a5679 Author: Vladimir N. Makarov Date: Thu Sep 14 10:26:48 2023 -0400 [RA]: Improve cost calculation of pseudos with equivalences RISCV target developers reported that RA can spill pseudo used in a loop although there are enough registers to assign. It happens when the pseudo has an equivalence outside the loop and the equivalence is not merged into insns using the pseudo. IRA sets up that memory cost to zero when the pseudo has an equivalence and it means that the pseudo will be probably spilled. This approach worked well for i686 (different approaches were benchmarked long time ago on spec2k). Although common sense says that the code is wrong and this was confirmed by RISCV developers. I've tried the following patch on I7-9700k and it improved spec17 fp by 1.5% (21.1 vs 20.8) although spec17 int is a bit worse by 0.45% (8.54 vs 8.58). The average generated code size is practically the same (0.001% difference). In the future we probably need to try more sophisticated cost calculation which should take into account that the equiv can not be combined in usage insns and the costs of reloads because of this. gcc/ChangeLog: * ira-costs.cc (find_costs_and_classes): Decrease memory cost by equiv savings. (cherry picked from commit 3c834d85f2ec42c60995c2b678196a06cb744959) Diff: --- gcc/ira-costs.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/gcc/ira-costs.cc b/gcc/ira-costs.cc index bdb1356af91..52c9c0b7608 100644 --- a/gcc/ira-costs.cc +++ b/gcc/ira-costs.cc @@ -1940,15 +1940,8 @@ find_costs_and_classes (FILE *dump_file) } if (i >= first_moveable_pseudo && i < last_moveable_pseudo) i_mem_cost = 0; - else if (equiv_savings < 0) - i_mem_cost = -equiv_savings; - else if (equiv_savings > 0) - { - i_mem_cost = 0; - for (k = cost_classes_ptr->num - 1; k >= 0; k--) - i_costs[k] += equiv_savings; - } - + else + i_mem_cost -= equiv_savings; best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; best = ALL_REGS; alt_class = NO_REGS;