From patchwork Tue Jun 6 04:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Dimitrov X-Patchwork-Id: 103556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3144617vqr; Mon, 5 Jun 2023 21:52:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6GwbV2if69DCyBpkMSlidh12+HMH5Q0pI1PWOHAheypTzZdl89m5WSNmTLrDOvGPUgWM5c X-Received: by 2002:a17:907:3da1:b0:969:e993:6ff0 with SMTP id he33-20020a1709073da100b00969e9936ff0mr7587479ejc.25.1686027149164; Mon, 05 Jun 2023 21:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686027149; cv=none; d=google.com; s=arc-20160816; b=EEDixcNgzeYcdx1yFJCgOQ32rfkk69J1WgDkyYRhkv4gzyLf7YY0SfxaYRiVXbsoXO d2NZOOdJUD/C+iOwrN9jCSyDwQj1kYsHU+VLPooCCBd7qDtS37hBAVSSwfhXoF7Y428/ x7x6dTk9RwVb62/vq7IjHKwSVfdfzrvHShbFtBHsCHBZ4tLe6VY1XYkeYTxnCA75H6E4 NdOWbYztGdapPRreon8WWDJnFHPVkMDDldhOZ6eTNMwd6uqWYqpPkspgSOI+s9DpRL2o IHb7KKIWmwwMhvIFUeEs/Y/z/bkPdDYf91Y0PIFvXMnw3NqehwF2kx9Wk8/q78PX9dxb nVSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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:dkim-signature :dmarc-filter:delivered-to; bh=4EH6QltyAXz4xMP4IMZoAAOtJyLxszhYBqfBwoJ0ZwQ=; b=IlY48rechgkPdJwvKHOgsLgTNNuVb2rjXpg6vVLjylbEP+hFPugZwm2llww/2ZyqHO buWnnEAS/iDkJbvS/cvCW6JNwIh9Jc+jhxwyjGr46+gIm0QcGqpxWHtZYvbq9eNk4aeM LZaAG36wxRxYDGjRAhnVNmUqtSsdNp6VxREkGmXzyeAcpc6GrTSogyhlJslXF1WRfkDi XuTrNm0zhcjc8JM4jz/W7X5IXWT6HEEcM29kqMcQEDZrz3EYtGDgyyoUinXpnvmHDCEl ALt9HWe8L6o63DrUZM43RDjTCWT0Wy1xucYhtALZsa7yIIYJ9J/hU2PcVqf2aLn4MRNt kEqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@dinux.eu header.s=default header.b=Bz0Cwg17; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb17-20020a1709077e9100b00977d0f093b5si3814506ejc.556.2023.06.05.21.52.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 21:52:29 -0700 (PDT) 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; dkim=fail header.i=@dinux.eu header.s=default header.b=Bz0Cwg17; 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 1267A3857348 for ; Tue, 6 Jun 2023 04:52:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server28.superhosting.bg (server28.superhosting.bg [217.174.156.11]) by sourceware.org (Postfix) with ESMTPS id D61BC3858416 for ; Tue, 6 Jun 2023 04:51:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D61BC3858416 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dinux.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinux.eu DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dinux.eu; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4EH6QltyAXz4xMP4IMZoAAOtJyLxszhYBqfBwoJ0ZwQ=; b=Bz0Cwg17ipV1FGSiKPCAfSlWgy +yU/ywjdncoSQ5mlblwJ4cak+kZDU9pqla0zbAoki+zM+GvUhpcH7PRQhcs9r3OY55uv+YEkElqn3 I+cXg/i5ty/29sIUX9I0TgEWcyZYz81M9KSIfCUjVrtGz0qdqnc4asRnBH9JT2d7jb/ssqLqdJghh SNiFS3oZglc/IKLVXZg2KyWd760en8EwEmgjRTxB9jt4f+AdaAFR/iLoNZK7xliyOAJ60/T64Lu15 8U7q1Tg2IbUrm3xHx8Ln9Vb2S1NPRlUGFZxsCyq52E1ximaSgCf1XfCeWfI63+PrZ1J58UpQc33JW QQz9oV+w==; Received: from [95.42.20.142] (port=38726 helo=kendros..) by server28.superhosting.bg with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1q6OfR-0007g8-EX; Tue, 06 Jun 2023 07:51:39 +0300 From: Dimitar Dimitrov To: gcc-patches@gcc.gnu.org Cc: Dimitar Dimitrov Subject: [PATCH] riscv: Fix insn cost calculation Date: Tue, 6 Jun 2023 07:51:29 +0300 Message-Id: <20230606045130.1687824-1-dimitar@dinux.eu> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server28.superhosting.bg X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - dinux.eu X-Get-Message-Sender-Via: server28.superhosting.bg: authenticated_id: dimitar@dinux.eu X-Authenticated-Sender: server28.superhosting.bg: dimitar@dinux.eu X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767927604065115113?= X-GMAIL-MSGID: =?utf-8?q?1767927604065115113?= When building riscv32-none-elf with "--enable-checking=yes,rtl", the following ICE is observed: cc1: internal compiler error: RTL check: expected code 'const_int', have 'const_double' in riscv_const_insns, at config/riscv/riscv.cc:1313 0x843c4d rtl_check_failed_code1(rtx_def const*, rtx_code, char const*, int, char const*) /mnt/nvme/dinux/local-workspace/gcc/gcc/rtl.cc:916 0x8eab61 riscv_const_insns(rtx_def*) /mnt/nvme/dinux/local-workspace/gcc/gcc/config/riscv/riscv.cc:1313 0x15443bb riscv_legitimate_constant_p /mnt/nvme/dinux/local-workspace/gcc/gcc/config/riscv/riscv.cc:826 0xdd3c71 emit_move_insn(rtx_def*, rtx_def*) /mnt/nvme/dinux/local-workspace/gcc/gcc/expr.cc:4310 0x15f28e5 run_const_vector_selftests /mnt/nvme/dinux/local-workspace/gcc/gcc/config/riscv/riscv-selftests.cc:285 0x15f37bd selftest::riscv_run_selftests() /mnt/nvme/dinux/local-workspace/gcc/gcc/config/riscv/riscv-selftests.cc:364 0x1f6fba9 selftest::run_tests() /mnt/nvme/dinux/local-workspace/gcc/gcc/selftest-run-tests.cc:111 0x11d1f39 toplev::run_self_tests() /mnt/nvme/dinux/local-workspace/gcc/gcc/toplev.cc:2185 Fix by following the spirit of the adjacent comment, and using the dedicated riscv_const_insns() function to calculate cost for loading a constant element. Infinite recursion is not possible because the first invocation is on a CONST_VECTOR, whereas the second is on a single element of the vector (e.g. CONST_INT or CONST_DOUBLE). Regression tested for riscv32-none-elf. No changes in gcc.sum and g++.sum. I don't have setup to test riscv64. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_const_insns): Recursively call for constant element of a vector. Signed-off-by: Dimitar Dimitrov --- gcc/config/riscv/riscv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 3954c89a039..c15da1d0e30 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -1310,7 +1310,7 @@ riscv_const_insns (rtx x) a general-purpose register. This means we need as many insns as it takes to load the constant into the GPR and one vmv.v.x. */ - return 1 + riscv_integer_cost (INTVAL (elt)); + return 1 + riscv_const_insns (elt); } }