From patchwork Tue Jun 6 23:05:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 104135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3724905vqr; Tue, 6 Jun 2023 16:06:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QMrENDgw5j0/4VMMbhrUpT8S3DWogl5jfRhe5leoaM2HwKJZ7h6pRGvT/+E6c07Q6ssIa X-Received: by 2002:a17:907:d0c:b0:966:5fac:2e52 with SMTP id gn12-20020a1709070d0c00b009665fac2e52mr10645114ejc.9.1686092782749; Tue, 06 Jun 2023 16:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686092782; cv=none; d=google.com; s=arc-20160816; b=xQoBBZX1Q3hYXjfy9Cl4qlg80RUGuX2hXQgVMPt83KeksxgAZJMQ6axu1Gike84WO/ +HLChyHnddk/bG13/81YYruo3hUduyylQOVaCL9PacrRhzLITRUT4m01Np6pdegccbNE 0oUjtQJZIAnDemq56DEFhFo42hkAFTmIsa/T4J8TEI6+dUPionnTTMbI75Qi7nPvvAlk l5cLP2ii1GwV7CdPMgm/Vs+h7BHCrncZMgt85HAf/CADUm9nmHRUME5vatRMcWEdgBCC Co3gZ8p6KOlcy1l3Qh3hwjHB7mcOLecjHnkCWme29rDUm6WaF/ChDgn/LKqod2dWP8zj 2XYg== 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-language:thread-index :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=2eJKHLdTF2svY3vytOGUNfR0PmLAO4/zTvQaKrUfHrQ=; b=TvXWoBYcFGdzD3+dYIMUPbMb0BGOx96kTJGtn82IiOcJU+bs6OwYWElhr4FD4yYSZs 0qD/zk6WXkgUodtRXTfkAlx6qKEigZ59fUXB0qpUmA4xcYKx5Vt0LVf1ckMFN4rDXTU1 PvjcZ+xY80Md7JhPNF6KX0tStyoVFezx+9aXTFWQA23An80s+3JzXLRIwtngYOZNEuJE d7NIxHU0WV3ZUxzkkM7WQikWZyMZCK2oozCrKnYuT/oYu7Uk+oSySho3pIH252wYR8Rk vgdAGtaRCd8DGuR2/cVA560dVFzlzMGvbo6839Uey+eXYqNcj8IX03ajFg8wca4PqDH9 9l3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=jnsf+nNs; 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 d17-20020a05640208d100b0051566d8bfecsi7311244edz.3.2023.06.06.16.06.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 16:06:22 -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=@nextmovesoftware.com header.s=default header.b=jnsf+nNs; 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 5F3EF385701C for ; Tue, 6 Jun 2023 23:06:09 +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 92A633858D38 for ; Tue, 6 Jun 2023 23:05:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92A633858D38 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=2eJKHLdTF2svY3vytOGUNfR0PmLAO4/zTvQaKrUfHrQ=; b=jnsf+nNsIrwKLUnt7Qx4z8Aerc TO/UmGE8rg5Tyh/4B8eHxoycrvITKTjex99UNeB8Sf76fjSrwwXonPuRfDbtfmDclyei5L811mPvq SHB59f4WMuHarBS+B4ihUgh/cJ5q9wVaZiy5LBTDEZvPcAAhzxGgyXoaZ/3acm2YKdHIcsTtZqN0n 4Ac3SNMLNPY1IxXDAoQKa5EAeC73HAsb24qNKw6CAM89/eAkV/tXjAFqVtGSHYwc9jdB7zDzw04AS 75SVh+Lu/R145zMSWm+6IZP+2QvZkFZUtYoRq7U2aTxrRpsRWXBsI7rQXH9P8ykVlfgKkHfwAGe9O zLnIY8Gw==; Received: from host86-169-41-81.range86-169.btcentralplus.com ([86.169.41.81]:64002 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1q6fkD-0006J5-2Q; Tue, 06 Jun 2023 19:05:41 -0400 From: "Roger Sayle" To: Cc: "'Uros Bizjak'" Subject: [x86 PATCH] PR target/31985: Improve memory operand use with doubleword add. Date: Wed, 7 Jun 2023 00:05:40 +0100 Message-ID: <037101d998cb$6aa8f120$3ffad360$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmYyw+pj1+zZOOrQ3iGoEDMlo9OQw== 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=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767996425722138353?= X-GMAIL-MSGID: =?utf-8?q?1767996425722138353?= This patch addresses the last remaining issue with PR target/31985, that GCC could make better use of memory addressing modes when implementing double word addition. This is achieved by adding a define_insn_and_split that combines an *add3_doubleword with a *concat3, so that the components of the concat can be used directly, without first being loaded into a double word register. For test_c in the bugzilla PR: Before: pushl %ebx subl $16, %esp movl 28(%esp), %eax movl 36(%esp), %ecx movl 32(%esp), %ebx movl 24(%esp), %edx addl %ecx, %eax adcl %ebx, %edx movl %eax, 8(%esp) movl %edx, 12(%esp) addl $16, %esp popl %ebx ret After: test_c: subl $20, %esp movl 36(%esp), %eax movl 32(%esp), %edx addl 28(%esp), %eax adcl 24(%esp), %edx movl %eax, 8(%esp) movl %edx, 12(%esp) addl $20, %esp ret If this approach is considered acceptable, similar splitters can be used for other doubleword operations. 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? 2023-06-07 Roger Sayle gcc/ChangeLog PR target/31985 * config/i386/i386.md (*add3_doubleword_concat): New define_insn_and_split combine *add3_doubleword with a *concat3 for more efficient lowering after reload. gcc/testsuite/ChangeLog PR target/31985 * gcc.target/i386/pr31985.c: New test case. Roger diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index e6ebc46..3592249 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -6124,6 +6124,36 @@ (clobber (reg:CC FLAGS_REG))])] "split_double_mode (mode, &operands[0], 2, &operands[0], &operands[3]);") +(define_insn_and_split "*add3_doubleword_concat" + [(set (match_operand: 0 "register_operand" "=r") + (plus: + (any_or_plus: + (ashift: + (zero_extend: + (match_operand:DWIH 2 "nonimmediate_operand" "rm")) + (match_operand: 3 "const_int_operand")) + (zero_extend: + (match_operand:DWIH 4 "nonimmediate_operand" "rm"))) + (match_operand: 1 "register_operand" "0"))) + (clobber (reg:CC FLAGS_REG))] + "INTVAL (operands[3]) == * BITS_PER_UNIT" + "#" + "&& reload_completed" + [(parallel [(set (reg:CCC FLAGS_REG) + (compare:CCC + (plus:DWIH (match_dup 1) (match_dup 4)) + (match_dup 1))) + (set (match_dup 0) + (plus:DWIH (match_dup 1) (match_dup 4)))]) + (parallel [(set (match_dup 5) + (plus:DWIH + (plus:DWIH + (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0)) + (match_dup 6)) + (match_dup 2))) + (clobber (reg:CC FLAGS_REG))])] + "split_double_mode (mode, &operands[0], 2, &operands[0], &operands[5]);") + (define_insn "*add_1" [(set (match_operand:SWI48 0 "nonimmediate_operand" "=rm,r,r,r") (plus:SWI48 diff --git a/gcc/testsuite/gcc.target/i386/pr31985.c b/gcc/testsuite/gcc.target/i386/pr31985.c new file mode 100644 index 0000000..a6de1b5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr31985.c @@ -0,0 +1,14 @@ +/* { dg-do compile { target ia32 } } */ +/* { dg-options "-O2" } */ + +void test_c (unsigned int a, unsigned int b, unsigned int c, unsigned int d) +{ + volatile unsigned int x, y; + unsigned long long __a = b | ((unsigned long long)a << 32); + unsigned long long __b = d | ((unsigned long long)c << 32); + unsigned long long __c = __a + __b; + x = (unsigned int)(__c & 0xffffffff); + y = (unsigned int)(__c >> 32); +} + +/* { dg-final { scan-assembler-times "movl" 4 } } */