From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0372_01D998D3.CC6D5920" 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 List-Id: This is a multipart message in MIME format. ------=_NextPart_000_0372_01D998D3.CC6D5920 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 -- ------=_NextPart_000_0372_01D998D3.CC6D5920 Content-Type: text/plain; name="patchad.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchad.txt" diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md=0A= index e6ebc46..3592249 100644=0A= --- a/gcc/config/i386/i386.md=0A= +++ b/gcc/config/i386/i386.md=0A= @@ -6124,6 +6124,36 @@=0A= (clobber (reg:CC FLAGS_REG))])]=0A= "split_double_mode (mode, &operands[0], 2, &operands[0], = &operands[3]);")=0A= =0A= +(define_insn_and_split "*add3_doubleword_concat"=0A= + [(set (match_operand: 0 "register_operand" "=3Dr")=0A= + (plus:=0A= + (any_or_plus:=0A= + (ashift:=0A= + (zero_extend:=0A= + (match_operand:DWIH 2 "nonimmediate_operand" "rm"))=0A= + (match_operand: 3 "const_int_operand"))=0A= + (zero_extend:=0A= + (match_operand:DWIH 4 "nonimmediate_operand" "rm")))=0A= + (match_operand: 1 "register_operand" "0")))=0A= + (clobber (reg:CC FLAGS_REG))]=0A= + "INTVAL (operands[3]) =3D=3D * BITS_PER_UNIT"=0A= + "#"=0A= + "&& reload_completed"=0A= + [(parallel [(set (reg:CCC FLAGS_REG)=0A= + (compare:CCC=0A= + (plus:DWIH (match_dup 1) (match_dup 4))=0A= + (match_dup 1)))=0A= + (set (match_dup 0)=0A= + (plus:DWIH (match_dup 1) (match_dup 4)))])=0A= + (parallel [(set (match_dup 5)=0A= + (plus:DWIH=0A= + (plus:DWIH=0A= + (ltu:DWIH (reg:CC FLAGS_REG) (const_int 0))=0A= + (match_dup 6))=0A= + (match_dup 2)))=0A= + (clobber (reg:CC FLAGS_REG))])]=0A= + "split_double_mode (mode, &operands[0], 2, &operands[0], = &operands[5]);")=0A= +=0A= (define_insn "*add_1"=0A= [(set (match_operand:SWI48 0 "nonimmediate_operand" "=3Drm,r,r,r")=0A= (plus:SWI48=0A= diff --git a/gcc/testsuite/gcc.target/i386/pr31985.c = b/gcc/testsuite/gcc.target/i386/pr31985.c=0A= new file mode 100644=0A= index 0000000..a6de1b5=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.target/i386/pr31985.c=0A= @@ -0,0 +1,14 @@=0A= +/* { dg-do compile { target ia32 } } */=0A= +/* { dg-options "-O2" } */=0A= +=0A= +void test_c (unsigned int a, unsigned int b, unsigned int c, unsigned = int d)=0A= +{=0A= + volatile unsigned int x, y;=0A= + unsigned long long __a =3D b | ((unsigned long long)a << 32);=0A= + unsigned long long __b =3D d | ((unsigned long long)c << 32);=0A= + unsigned long long __c =3D __a + __b;=0A= + x =3D (unsigned int)(__c & 0xffffffff);=0A= + y =3D (unsigned int)(__c >> 32);=0A= +}=0A= +=0A= +/* { dg-final { scan-assembler-times "movl" 4 } } */=0A= ------=_NextPart_000_0372_01D998D3.CC6D5920--