From patchwork Tue May 17 16:44:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1632446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=F41FRTnJ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L2hmP3h9sz9s2R for ; Wed, 18 May 2022 02:44:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA4633858016 for ; Tue, 17 May 2022 16:44:34 +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 [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 72AA53858D3C for ; Tue, 17 May 2022 16:44:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72AA53858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com 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=w6W6YypC5VkH168YJTYX4gA3oZ5pIIwHO+pcubhen4U=; b=F41FRTnJHZ5QkjWSW6QBcznIcq TO3LPKFV4vaxXvmZZtFTKta7ZSI6NSQ7XNgrUFSXLJA+ANsvbZ/cRs+fGwzZ/PetoDscOPAEnYvK2 Da2pNC8kkaDXXvKl+gowB0AHNKz22pxL3iYpwJJb0kaoh175ZmzxI0VlvoCfm88Hg1JDnw0KNUf1J EaLy5Vf4DEGbZo3vl2TDll6DvVYYbqU+g4BTAqSIIe8JGEnIuQPXRwQmompSDD6ykojD6Gioffo6t PhUM1mg7XLUKIE4G4J2OFjNizwywVHbGG0j8j9fLBuf2d7VVM0heIZoyd9O2EpZpKAiXOEHftsUR5 eo7+6CGA==; Received: from host109-154-46-241.range109-154.btcentralplus.com ([109.154.46.241]:51625 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nr0J4-0000w4-Pq; Tue, 17 May 2022 12:44:23 -0400 From: "Roger Sayle" To: Subject: [x86 PATCH] Correct ix86_rtx_cost for multi-word multiplication. Date: Tue, 17 May 2022 17:44:20 +0100 Message-ID: <00b701d86a0d$5c648400$152d8c00$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdhqDJvczZwZbiPXTK2NooJb63maJg== 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=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, 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.29 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 Sender: "Gcc-patches" This is the i386 backend specific piece of my revised patch for PR middle-end/98865, where Richard Biener has suggested that I perform the desired transformation during RTL expansion where the backend can control whether it is profitable to convert a multiplication into a bit-wise AND and a negation. This works well for x86_64, but alas exposes a latent bug with -m32, where a DImode multiplication incorrectly appears to be cheaper than negdi2+anddi3(!?). The fix to ix86_rtx_costs is to report that a DImode (multi-word) multiplication actually requires three SImode multiplications and two SImode additions. This also corrects the cost of TImode multiplication on TARGET_64BIT. 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. This change avoids the need for a !ia32 target selector for the upcoming new test case gcc.target/i386/pr98865.c. Ok for mainline? 2022-05-17 Roger Sayle gcc/ChangeLog * config/i386/i386.cc (ix86_rtx_costs) [MULT]: When mode size is wider than word_mode, a multiplication costs three word_mode multiplications and two word_mode additions. Thanks in advance, Roger diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 86752a6..e8a2229 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -20634,7 +20634,17 @@ ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno, op0 = XEXP (op0, 0), mode = GET_MODE (op0); } - *total = (cost->mult_init[MODE_INDEX (mode)] + int mult_init; + // Double word multiplication requires 3 mults and 2 adds. + if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) + { + mult_init = 3 * cost->mult_init[MODE_INDEX (word_mode)] + + 2 * cost->add; + nbits *= 3; + } + else mult_init = cost->mult_init[MODE_INDEX (mode)]; + + *total = (mult_init + nbits * cost->mult_bit + rtx_cost (op0, mode, outer_code, opno, speed) + rtx_cost (op1, mode, outer_code, opno, speed));