From patchwork Wed Sep 2 17:51:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Yaduo X-Patchwork-Id: 142749 X-Patchwork-Delegate: rdapp.gcc@gmail.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F35884BA9008 for ; Wed, 2 Sep 2026 17:52:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F35884BA9008 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=ta6VnIeV X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by sourceware.org (Postfix) with ESMTPS id B6E9E4BA2E1F for ; Wed, 2 Sep 2026 17:51:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6E9E4BA2E1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.alibaba.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B6E9E4BA2E1F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788371516; cv=none; b=Bu/w0jUcmm0YR501g3xXARUGh+a79LnSolupaOrMQm7p5iCVmQT55OYM3tSresR4PhM2co3oHkuZpM7J0VtWTbfiWXiPqH66daUitfporW8MCQ9lBZO4bLqQupT8AKGc+JJweHWI8yveJP0xdRhssFzpeT4p/Mc/beUdilOKTNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788371516; c=relaxed/simple; bh=RCJ2SXKkopqychvE0Q5hoOTXyrKgukmEEn7p9aCNvgI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Qa8wCt+xMrgIGcFVOCcuEfdajjcEyndX4I6Fnr5o5L/kfoqCeNsQvagZ5yLoSPOpgBuHPKL03cPsx77vOw3BbX/R6ThpKi3c8qWJkjwER1zPCRpTyoqTkuIOPX9u9YmGu+xuzfjP72bqS4tk/J343pAlQM58SvdzAKKfOnNVga8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=ta6VnIeV DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B6E9E4BA2E1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1788371512; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=ZZXnFQZaxDkGH+chzNy6oq6IehObeLma3xd60/x5xaQ=; b=ta6VnIeV2l0Pe/pVKaqitlRgXiwPHCp8ptSu6FpYK0AVzhRPwcXomxq7X2QRADEz1zDPCyvZJ0dblzluaexaDxOqpM1J4xdxOYElGgdzZoCqectPgrxBgalRP90JyxCHpXoizzBmClXhN5vvFrYIhzdJLGvTlpwIrgJWNB41DRQ= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R151e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033032089153; MF=wangyaduo@linux.alibaba.com; NM=1; PH=DS; RN=4; SR=0; TI=SMTPD_---0XADFp0h_1788371510; Received: from localhost.localdomain(mailfrom:wangyaduo@linux.alibaba.com fp:SMTPD_---0XADFp0h_1788371510 cluster:ay36) by smtp.aliyun-inc.com; Thu, 03 Sep 2026 01:51:52 +0800 From: Wang Yaduo To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Wang Yaduo Subject: [PATCH] RISC-V: Skip vector adjustments for scalar costing Date: Thu, 3 Sep 2026 01:51:48 +0800 Message-ID: <20260902175149.70623-1-wangyaduo@linux.alibaba.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 X-Spam-Status: No, score=-27.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@gcc.gnu.org Recovered scalar types are needed by the base cost hook, but they must not trigger vector-specific statement cost adjustments. gcc/ChangeLog: * config/riscv/riscv-vector-costs.cc (costs::add_stmt_cost): Skip statement cost adjustments for scalar costing. --- When costing scalar IL, vectype is null and 32dc4bc recovers a type from the statement LHS. The LHS can itself be vector-typed, however, so this can produce a vectype that is wrong for the scalar cost being computed. This happens for the 512-element constructor in combine-4.c. Its root statement has a vector(512) long int LHS. Recovering that type while computing SCALAR_COST lets adjust_stmt_cost apply M8 scaling, raising the scalar cost from 1 to 8. An SLP alternative using 512-byte vectors, whose cost is 6, then appears profitable and expands the constructor through a 4096-byte stack temporary. This removes one of the four expected vslideup.vx instructions. Require m_cost_type != SCALAR_COST before calling adjust_stmt_cost. The recovered type is still passed to builtin_vectorization_cost, but cannot trigger vector-specific adjustments during scalar costing. Tested the full gcc.target/riscv testsuite on rv64gcv, including execution tests; no new FAIL, XPASS, UNRESOLVED, or ERROR results versus 32dc4bc^. gcc/config/riscv/riscv-vector-costs.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv-vector-costs.cc b/gcc/config/riscv/riscv-vector-costs.cc index dfb80bee67..41a15ae220 100644 --- a/gcc/config/riscv/riscv-vector-costs.cc +++ b/gcc/config/riscv/riscv-vector-costs.cc @@ -1622,7 +1622,7 @@ costs::add_stmt_cost (int count, vect_cost_for_stmt kind, m_unrolled_vls_stmts += count * m_unrolled_vls_niters; } - if (vectype) + if (m_cost_type != SCALAR_COST && vectype) stmt_cost = adjust_stmt_cost (kind, loop_vinfo, stmt_info, node, vectype, stmt_cost);