From patchwork Sun Mar 3 12:56:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 209304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp902048dyc; Sun, 3 Mar 2024 04:57:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXO56bBbT9hp68bLQZXfMlIS0Atko7vLkZMec2Q2XuBYnqq9lXGvtlDu6xu1dZwa8/NnQ7Pz5OJq0hTcQtJ569CiOZ4iw== X-Google-Smtp-Source: AGHT+IG5xBqgFM8YEFIEgiuS8eGXpATw4U02OQTE33OIFmXxQhbOREwhmDjlHx0CR5s6JCQyDbt+ X-Received: by 2002:a05:620a:444e:b0:788:25e5:9199 with SMTP id w14-20020a05620a444e00b0078825e59199mr1190305qkp.26.1709470619873; Sun, 03 Mar 2024 04:56:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709470619; cv=pass; d=google.com; s=arc-20160816; b=tqw6xn4hc2MoG7/qjxfXGzA/NJ1QwYCnrhK++tqANPPgO9BCU5gPl8enXrClfvhjC8 uWepnSJE+tdouzFKRHZahRckvnqVcx8By8F71DZ1n95nZvoZnScGasK6xBM+1O80V23F Upsndvz/4ai5hsltfboqYDYxPbopJDD1En/Ks6gEaGLEh6y6mB+e7yBAxCYhdWC7VM4y wYhBTKf+pdXfLN1vJkGdKVPHtUbp570eqtIYtwfIOJBXaTEqLcIOEq7HU87Jjdp/d2KB Nrgpnzi5LSMRous/xRPlA9/YwxJOUJk6KfnRAr8KRz94rwGdjDyITlj88QghSlKJx1z3 N8uw== 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-language:thread-index :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=vccE2mwZxCXwVpR7V9zcxuOVa4Qsraap18E9lKATXVg=; fh=ZObKuiLHqS0qoMMC1BEEzNyeT+IyeAqVtRTZKxBpTfQ=; b=zr9o1qSdkjUYLaUPAPRH0I7vV1bhUolGXYw6XvzYl3ZdyH5iSIOo2b3+ENiO5eV8sH +rd+iYnmoOPz2f9gRossvSSJnSzipDcyVZNSfOy0vumH4LurOj9Q85yk/OU+ztudjZQP lxEfbSIzco99PFGs9SzpksQC3w/FQHN1hhKTHxKxpNPZ6m+BudXveHe40iURcPgkdmAv 7JJ6F6lvPLgQzThDF7rF8WFKYyjIVdIakXQ5fDpyfUwe0kZusvoZf39ZARo7DiO2kDl6 prj/5HHQ/6bXPf5oeebV87ROFzGf5aOiWGkG9Cqf/3QTE6Gnl7WJqmLx8He8KAtR57Eq Y1yw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=P6FkkkPR; 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 wh23-20020a05620a56d700b0078805861fc6si5570147qkn.653.2024.03.03.04.56.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 04:56:59 -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; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=P6FkkkPR; 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 91B073858413 for ; Sun, 3 Mar 2024 12:56:59 +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 9BFFA3858C66 for ; Sun, 3 Mar 2024 12:56:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BFFA3858C66 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 9BFFA3858C66 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=1709470578; cv=none; b=DLTEUf4IOq0rCund2HcA3hnb2WScWvb3ijBMBS2SSSb90hh/THAX+M448dr+T0YJSItlfDV/TnxgVcxj6Sc5R2DrEob3bhWPIhY7eWaLGS3v2NnY5/+6O8ulYQRjqJdHk4K2vQCuLYFoQQ47WMW+l0M0zYm3uZ2rWteeMW8o7zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709470578; c=relaxed/simple; bh=B4kk4zaVsXVzHmxnmfyB5aoCcdwwu/1LmrY6K+ZJb98=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UbwK1OG1BiQwXDYJQYhtLa0QZwmLVCGhrgsCaI73+35FLawcNczK0yjwa+mfQBwkH9csq4S1BmE4I1ItXicjlkDIF3Vw35cOhCMZo+3soK/nxdLzfDR5PWadukDCdiglx5Xj4EO2wmQkCxsu2gUEbP/y8uiE/xaf66bFQjB1VM0= 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=vccE2mwZxCXwVpR7V9zcxuOVa4Qsraap18E9lKATXVg=; b=P6FkkkPRlNKoD/oCQfTUAADQv6 7peujNhf3CvRDuOvkyoszo8qDPrtaOO/4kLZCAIogTAzusJaHmTUJyqAy5MzOjWmT7JxvPeLmHts7 09OUh1qldiknZQP5iSpC+TJ/LMyOBB3M3WNe9aD3+7TDbzDFmNubcWARkhTscijwZ/n25u6E6hkMY T3NnBmH5U+b0JD5/iJMfvg1ViNfpB6hmWK+pTBPGKeh1RSYfwIncMRwTZLc0e1YAGb3xzabkgWWPV lR+/8qFc8yjYaqRQShm78kvXAqCF7grtUQqPwT7TNGUhqkBkOsoQTxAWpegrM/b9WoKaSBobF4WHL /4ScvCSQ==; Received: from 65.205-252-62.static.virginmediabusiness.co.uk ([62.252.205.65]:23709 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rglO3-00B33Z-2G; Sun, 03 Mar 2024 07:56:15 -0500 From: "Roger Sayle" To: Cc: "'Richard Sandiford'" Subject: [PATCH] PR target/114187: Fix ?Fmode SUBREG simplification in simplify_subreg. Date: Sun, 3 Mar 2024 12:56:12 -0000 Message-ID: <000901da6d6a$2d642630$882c7290$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdptafPaXTi1sgOcS+qUGGVy5HbwEg== 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=-8.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_SBL_CSS, 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.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: 1792509864663687677 X-GMAIL-MSGID: 1792509864663687677 This patch fixes PR target/114187 a typo/missed-optimization in simplify-rtx that's exposed by (my) changes to x86_64's parameter passing. The context is that construction of double word (TImode) values now uses the idiom: (ior:TI (ashift:TI (zero_extend:TI (reg:DI x)) (const_int 64 [0x40])) (zero_extend:TI (reg:DI y))) Extracting the DImode highpart and lowpart halves of this complex expression is supported by simplications in simplify_subreg. The problem is when the doubleword TImode value represents two DFmode fields, there isn't a direct simplification to extract the highpart or lowpart SUBREGs, but instead GCC uses two steps, extract the DImode {high,low} part and then cast the result back to a floating point mode, DFmode. The (buggy) code to do this is: /* If the outer mode is not integral, try taking a subreg with the equivalent integer outer mode and then bitcasting the result. Other simplifications rely on integer to integer subregs and we'd potentially miss out on optimizations otherwise. */ if (known_gt (GET_MODE_SIZE (innermode), GET_MODE_SIZE (outermode)) && SCALAR_INT_MODE_P (innermode) && !SCALAR_INT_MODE_P (outermode) && int_mode_for_size (GET_MODE_BITSIZE (outermode), 0).exists (&int_outermode)) { rtx tem = simplify_subreg (int_outermode, op, innermode, byte); if (tem) return simplify_gen_subreg (outermode, tem, int_outermode, byte); } The issue/mistake is that the second call, to simplify_subreg, shouldn't use "byte" as the final argument; the offset has already been handled by the first call, to simplify_subreg, and this second call is just a type conversion from an integer mode to floating point (from DImode to DFmode). Interestingly, this mistake was already spotted by Richard Sandiford when the optimization was originally contributed in January 2023. https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610920.html >> Richard Sandiford writes: >> Also, the final line should pass 0 rather than byte. Unfortunately a miscommunication/misunderstanding in a later thread https://gcc.gnu.org/pipermail/gcc-patches/2023-February/612898.html resulted in this correction being undone. Alas the lack of any test cases when the optimization was added/modified potentially contributed to this lapse. Using lowpart_subreg should avoid/reduce confusion in future. 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-03-03 Roger Sayle gcc/ChangeLog PR target/114187 * simplify-rtx.cc (simplify_context::simplify_subreg): Call lowpart_subreg to perform type conversion, to avoid confusion over the offset to use in the call to simplify_reg_subreg. gcc/testsuite/ChangeLog PR target/114187 * g++.target/i386/pr114187.C: New test case. Thanks in advance, Roger diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc index 36dd522..dceaa13 100644 --- a/gcc/simplify-rtx.cc +++ b/gcc/simplify-rtx.cc @@ -7846,7 +7846,7 @@ simplify_context::simplify_subreg (machine_mode outermode, rtx op, { rtx tem = simplify_subreg (int_outermode, op, innermode, byte); if (tem) - return simplify_gen_subreg (outermode, tem, int_outermode, byte); + return lowpart_subreg (outermode, tem, int_outermode); } /* If OP is a vector comparison and the subreg is not changing the diff --git a/gcc/testsuite/g++.target/i386/pr114187.C b/gcc/testsuite/g++.target/i386/pr114187.C new file mode 100644 index 0000000..69912a9 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/pr114187.C @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct P2d { + double x, y; +}; + +double sumxy_p(P2d p) { + return p.x + p.y; +} + +/* { dg-final { scan-assembler-not "movq" } } */ +/* { dg-final { scan-assembler-not "xchg" } } */