From patchwork Wed Dec 20 08:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "demin.han" X-Patchwork-Id: 181521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2489806dyi; Wed, 20 Dec 2023 00:15:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEooDf27HFycPp/qsuMnFn8f0FyliSxjIw6dVpCVVhL3/uTz/0LW+EbaJH/ZlXRc1CJgmR3 X-Received: by 2002:a05:6808:220c:b0:3b9:d8bb:8ff6 with SMTP id bd12-20020a056808220c00b003b9d8bb8ff6mr19263877oib.31.1703060156128; Wed, 20 Dec 2023 00:15:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703060156; cv=pass; d=google.com; s=arc-20160816; b=0kKpoe1GbrG44rMsRpmNvZNrdS6wXPL1dZS+djfkqOR6qqmX0hXJ1RqoEUS7hMdQvl b0hMZvSnMdl+36+e/3/KS0ExzeOXsiLwNlY4eCNemz/qnOqbXCj/6L0Z0SM6vBWl0egi CrWGVO2q74ydS/BOQI3Pe4nyvzKJydOS4pz8pPozqsPuXxEEAh8wccw/CJc5yXGdvM35 AvYvthqGLnJW40Or+w3J6Tbfafzbw/Ubf/jw4Dkwxlfxz5l/0Mf+A5Ms9Ete7lfGo6un X2roj/49UOFHqWjdMVRsnFkPCmogPf/HdNDFKqT8S4YoM533jSEgMLeh+Xh4KQtp4A1U HPzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=Btq7w/zGSyzWmx0wlzeNK3xKuF5N+bp4Ts7qcbIoDSA=; fh=damxhKJ+GrdknhcErj34w/RFbs0Uy0nIZaPvrimAj+I=; b=qRjv48/vw93sub6pajC6K4pbExZh1Fpxla7HXQIaeJuYj0MS2ACJLj7bHyoteWgSDy OuOGkw0OJcQSU/DTOY54JrBEiA5PYXkC8vpjurLEtn61lV6VV1RbT0v7qEouWAvC6djw 9Q03OM+ME4Y3BcjH4bZ2xkZxZigfXYLm8JTyLx8YBnRYSb2lBZH1ChLUaH2r14oN99WU LrDqnpBn+2HIYVbbnXiFdMLIgGN7QO//TuVejWBIDMsMgsvdVti5q1ByYJZTyllYP0YZ RWkbQqJFY8v0veGd1pEeSod09vGHUKzBdppG0Q76SrH8P6YzVUjagfCKNY7jx8Wy9had e4HQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id br16-20020a05620a461000b0077da5d169bfsi29083829qkb.362.2023.12.20.00.15.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 00:15:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC5CC3861864 for ; Wed, 20 Dec 2023 08:15:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by sourceware.org (Postfix) with ESMTPS id 73F573857437 for ; Wed, 20 Dec 2023 08:15:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73F573857437 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=starfivetech.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 73F573857437 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=61.152.239.71 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703060131; cv=none; b=dfpaNSEAanIFVBYHqflFkvHtnX+f85Tn0Oel5PcwUOghrSbQzdaQiAA0QuofC/0LvQP0IahJIDbRBXBbeq6N207PFstV5GXcMFE2EgDMyJcZVgKdKy84jGCo+/xd+TGIHsAajyXB+r/HdK0p/U2vCroVUtUE/5ZEy0SGRVdujIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703060131; c=relaxed/simple; bh=o0u9mvqyzG3J0lRsy8ycKe+1DGBzYgc9Q0D8o2D+Voc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=m3F0QDni2M7eFJGyu7NvYoDt5babIP+QmSvVJqdxS8JwDGORZWY1doxaN5S1eE9KSHQSwVC3AxAk57jMQjTph9AJ2QbISjRY4G9Tki0KMRssUUVf4O59/uF9CGVZI9oanF2wO8xVdOVnqMCPlR7/Y80UVsvMcLsqJ3/+7RvW9Lo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id EFC96807D; Wed, 20 Dec 2023 16:15:22 +0800 (CST) Received: from EXMBX168.cuchost.com (172.16.6.78) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 20 Dec 2023 16:15:23 +0800 Received: from damon-pc.localdomain (113.72.145.47) by EXMBX168.cuchost.com (172.16.6.78) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 20 Dec 2023 16:15:22 +0800 From: demin.han To: CC: , Subject: [PATCH] RISC-V: Fix calculation of max live vregs Date: Wed, 20 Dec 2023 16:15:37 +0800 Message-ID: <20231220081537.2013818-1-demin.han@starfivetech.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Originating-IP: [113.72.145.47] X-ClientProxiedBy: EXCAS064.cuchost.com (172.16.6.24) To EXMBX168.cuchost.com (172.16.6.78) X-YovoleRuleAgent: yovoleflag X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785788006226131142 X-GMAIL-MSGID: 1785788006226131142 For the stmt _1 = _2 + _3, assume that _2 or _3 not used after this stmt. _1 can use same register with _2 or _3 if without early clobber. Two registers are needed, but current calculation is three. This patch preserves point 0 for bb entry and excludes its def when calculates live regs of certain point. Signed-off-by: demin.han gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc (max_number_of_live_regs): Fix max live vregs calc (preferred_new_lmul_p): Ditto gcc/testsuite/ChangeLog: * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-7.c: Moved to... * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-10.c: ...here. * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-4.c: Moved to... * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c: ...here. Signed-off-by: demin.han --- gcc/config/riscv/riscv-vector-costs.cc | 10 +++++----- .../rvv/{dynamic-lmul2-7.c => dynamic-lmul4-10.c} | 6 +++--- .../rvv/{dynamic-lmul4-4.c => dynamic-lmul8-11.c} | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) rename gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/{dynamic-lmul2-7.c => dynamic-lmul4-10.c} (79%) rename gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/{dynamic-lmul4-4.c => dynamic-lmul8-11.c} (87%) diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index e7bc9ed5233..a316603e207 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -123,7 +123,7 @@ compute_local_program_points ( /* Collect the stmts that is vectorized and mark their program point. */ for (i = 0; i < nbbs; i++) { - int point = 0; + int point = 1; basic_block bb = bbs[i]; vec program_points = vNULL; if (dump_enabled_p ()) @@ -300,13 +300,13 @@ max_number_of_live_regs (const basic_block bb, unsigned int i; unsigned int live_point = 0; auto_vec live_vars_vec; - live_vars_vec.safe_grow_cleared (max_point + 1, true); + live_vars_vec.safe_grow_cleared (max_point, true); for (hash_map::iterator iter = live_ranges.begin (); iter != live_ranges.end (); ++iter) { tree var = (*iter).first; pair live_range = (*iter).second; - for (i = live_range.first; i <= live_range.second; i++) + for (i = live_range.first + 1; i <= live_range.second; i++) { machine_mode mode = TYPE_MODE (TREE_TYPE (var)); unsigned int nregs @@ -485,7 +485,7 @@ update_local_live_ranges ( if (!program_points_per_bb.get (e->src)) continue; unsigned int max_point - = (*program_points_per_bb.get (e->src)).length () - 1; + = (*program_points_per_bb.get (e->src)).length (); live_range = live_ranges->get (def); if (!live_range) continue; @@ -571,7 +571,7 @@ preferred_new_lmul_p (loop_vec_info other_loop_vinfo) { basic_block bb = (*iter).first; unsigned int max_point - = (*program_points_per_bb.get (bb)).length () - 1; + = (*program_points_per_bb.get (bb)).length () + 1; if ((*iter).second.is_empty ()) continue; /* We prefer larger LMUL unless it causes register spillings. */ diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-7.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-10.c similarity index 79% rename from gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-7.c rename to gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-10.c index 636332dbb62..74e629168f8 100644 --- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-7.c +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-10.c @@ -17,10 +17,10 @@ bar (int *x, int a, int b, int n) return sum1 + sum2; } -/* { dg-final { scan-assembler {e32,m2} } } */ +/* { dg-final { scan-assembler {e32,m4} } } */ /* { dg-final { scan-assembler-not {jr} } } */ /* { dg-final { scan-assembler-times {ret} 2 } } * /* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */ -/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */ -/* { dg-final { scan-tree-dump "Maximum lmul = 2" "vect" } } */ +/* { dg-final { scan-tree-dump "Maximum lmul = 4" "vect" } } */ +/* { dg-final { scan-tree-dump-not "Maximum lmul = 2" "vect" } } */ /* { dg-final { scan-tree-dump-not "Maximum lmul = 1" "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-4.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c similarity index 87% rename from gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-4.c rename to gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c index 01a359bc7c8..01c976dd67b 100644 --- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-4.c +++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c @@ -39,9 +39,9 @@ void foo2 (int64_t *__restrict a, } } -/* { dg-final { scan-assembler {e64,m4} } } */ +/* { dg-final { scan-assembler {e64,m8} } } */ /* { dg-final { scan-assembler-not {csrr} } } */ -/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */ -/* { dg-final { scan-tree-dump "Maximum lmul = 4" "vect" } } */ +/* { dg-final { scan-tree-dump "Maximum lmul = 8" "vect" } } */ +/* { dg-final { scan-tree-dump-not "Maximum lmul = 4" "vect" } } */ /* { dg-final { scan-tree-dump-not "Maximum lmul = 2" "vect" } } */ /* { dg-final { scan-tree-dump-not "Maximum lmul = 1" "vect" } } */