From patchwork Wed May 22 15:15:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1937871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=Sj2BDe3q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VkvzN4rSWz1ydW for ; Thu, 23 May 2024 01:16:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED3673865C24 for ; Wed, 22 May 2024 15:16:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [69.48.154.134]) by sourceware.org (Postfix) with ESMTPS id B44F43865C33 for ; Wed, 22 May 2024 15:15:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B44F43865C33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B44F43865C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=69.48.154.134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716390918; cv=none; b=Or4r6AM1cA2+uwSbuO7rN0a3J4rAuBTj606D61VPR3st0H/Tgr1Ll9dGuSgDJrRpPy9gvPOeJXsfd0XcMk+0MKIqKucIZ05r8ULibNHs52Ms/a8HMIuE1Ge74eh78zpxI1+Th+DZ1wCwsD2Uwh8KCoCM/QeVk2hNCmGZ3UO+FEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716390918; c=relaxed/simple; bh=eDUldmsSEK+Mhr7pzSkxcya2fGhWCYx0JHW8DBUBtk4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZObuzx/veFASOTLb16rUtd6idZTWFfW+o5hH7enKtR2gLsKVTtNYJ/Z83Zuf9rwNaEXWBW4nWCUBqfzis5Uemc9putmbdgZoy41O9PsQtm81zqJax2Hj0WKGwe0/r4vS5p8HtlZr8NBynANmEKTIMwa9DTpP54P+hwNGNmz1iCQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: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=FJbTM6qL1T7nEtiSAwgE5I5KtnuZfNPwTNk1XvmvvOc=; b=Sj2BDe3q82rD+f4j/23E5mDTWx oJDjUDdekorJy9GXboBtJTGZ7cdG3NCxEeIhQPfjioyljB1DcmVIwrg0S+d2qr//k25VFyRDrEULz qtISjMtcbiwoWOTcQohIgwK+Cn0C4K5XEfk6lvGYu+NcsWK6/VAHWA/yV5c2McIGDexdpIDZ1Lq2g L46HlHleXcESD+BII8A+8yzQq672fZ75TUR75Qvi4fcWE6HGBAnbzD9jFK/qffFjw4pECOcCa2jTT 6/O6utx7j3hA4FlI0g2NSRT1SCnM+byWhqtRAj2uDIzF5wogy/XOHrBO925A8cLZPvXbjQgiQAY4E dZq7zvZQ==; Received: from [185.62.158.67] (port=59259 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1s9ngQ-00000004Chk-3fRD; Wed, 22 May 2024 11:15:15 -0400 From: "Roger Sayle" To: Cc: "'Uros Bizjak'" Subject: [x86_64 PATCH] Correct insn_cost of movabsq. Date: Wed, 22 May 2024 16:15:13 +0100 Message-ID: <007701daac5a$d94d0af0$8be720d0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdqsWVE9+eGUyp4JQ42gj82uetAvhQ== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LOTS_OF_MONEY, SPF_HELO_NONE, SPF_PASS, TXREP 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+incoming=patchwork.ozlabs.org@gcc.gnu.org This single line patch fixes a strange quirk/glitch in i386's rtx_costs, which considers an instruction loading a 64-bit constant to be significantly cheaper than loading a 32-bit (or smaller) constant. Consider the two functions: unsigned long long foo() { return 0x0123456789abcdefULL; } unsigned int bar() { return 10; } and the corresponding lines from combine's dump file: insn_cost 1 for #: r98:DI=0x123456789abcdef insn_cost 4 for #: ax:SI=0xa The same issue can be seen in -dP assembler output. movabsq $81985529216486895, %rax # 5 [c=1 l=10] *movdi_internal/4 The problem is that pattern_costs interpretation of rtx_costs contains "return cost > 0 ? cost : COSTS_N_INSNS (1)" where a zero value (for example a register or small immediate constant) is considered special, and equivalent to a single instruction, but all other values are treated as verbatim. Hence to make x86_64's 10-byte long movabsq instruction slightly more expensive than a simple constant, rtx_costs needs to return COSTS_N_INSNS(1)+1 and not 1. With this change, the insn_cost of movabsq is the intended value 5: insn_cost 5 for #: r98:DI=0x123456789abcdef and movabsq $81985529216486895, %rax # 5 [c=5 l=10] *movdi_internal/4 [I'd originally tried fixing this by adding a ix86_insn_cost target hook, but the testsuite is very sensitive to the costing of insns]. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2024-05-22 Roger Sayle gcc/ChangeLog * config/i386/i386.cc (ix86_rtx_costs) : A CONST_INT that isn't x86_64_immediate_operand requires an extra (expensive) movabsq insn to load, so return COSTS_N_INSNS (1) + 1. Thanks in advance, Roger diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index b4838b7..b4a9519 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -21569,7 +21569,7 @@ ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno, if (x86_64_immediate_operand (x, VOIDmode)) *total = 0; else - *total = 1; + *total = COSTS_N_INSNS (1) + 1; return true; case CONST_DOUBLE: