From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id 0217F385840D for ; Wed, 7 Jun 2023 07:08:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0217F385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-75d54faa03eso450739985a.1 for ; Wed, 07 Jun 2023 00:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686121681; x=1688713681; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y4U/7Vv9vez/5jrKJBU8oFbgtpfc83mJkScdaQc/MSg=; b=beLv60Sd1NqWNj5Kfxq7ZQOvTsNFg3eATk4BdRFHGvXMZxPRbyt5rdJBkM3lonesrR GqoSfN1/PxmbHRkda5StdfyIj1shJ3NRc8Y8vd2SRG+mAPX8uDlur9EY4GUlx1eDU/f1 0QwiZLNSXEelqp3lRnJjim2X8IKMBUF2bJPYl/99f/abq4KBkoTbiHmZXDw6uvo/9sTc +4tjILilRWFUPg/eyLK0fdG8im/BRoy8duP3CrcWMTBsJqV3a1gUQ6w9Vpkt9x1bxPbS YjF+I0g3HP8W4qTHrQvvVpeLDZPjfLrTfs4JQ0gkQR5riBOK5XZH87lkdOwJM+iM/SIg obAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686121681; x=1688713681; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y4U/7Vv9vez/5jrKJBU8oFbgtpfc83mJkScdaQc/MSg=; b=dt14iJ1gjFxfvLvMZTB3rfIRtB/0jjVpsvTGeNEPkYg0WWm4waayT8mgpQWlr6VhtS 8XOqE/xwpQbiEv/i5MVMO3Uy8OS9ZCSdb3DKHIpA5eDUjh207Stg26Y4S26lD1tA58c8 TUbsvjHVuLVVhNZxUdAPswt6LMowTDuWUzJ7C4ma9C82jPfYKxgcISlXsPrHMe7zlJkb QZQif+5ysRaqYbS4DwvQmGroSH3591v2+XHM4FpeobYGkcwcogc4Hj3TqfUVZp08cdln 8ZO0v9c2+C8/PMtFbTgrvzVOcH+DEAcc80MxsluavWyze7BUKCEHmtSZwUyx9EXNttmO 9RGA== X-Gm-Message-State: AC+VfDw2lssMyErSrqjogVTv08wmK8kCZ92fMHdTiowQjKM5zRVWHzug ZclIvp/GPS1a1EZVI+qiDO/OTDPZPJcfCKanAbY= X-Google-Smtp-Source: ACHHUZ5q9dpfTcPKwdMD98FiwMyvL7GYz8gS3QNjOxwzBd302sh2tIvlHVlh3XchBRq3UH9IwTRDLIifzyFZZ0beJkM= X-Received: by 2002:a05:6214:2526:b0:626:ff6:f48a with SMTP id gg6-20020a056214252600b006260ff6f48amr2222219qvb.13.1686121681244; Wed, 07 Jun 2023 00:08:01 -0700 (PDT) MIME-Version: 1.0 References: <037101d998cb$6aa8f120$3ffad360$@nextmovesoftware.com> In-Reply-To: From: Uros Bizjak Date: Wed, 7 Jun 2023 09:07:50 +0200 Message-ID: Subject: Re: [x86 PATCH] PR target/31985: Improve memory operand use with doubleword add. To: Roger Sayle Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,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: On Wed, Jun 7, 2023 at 8:32=E2=80=AFAM Uros Bizjak wrot= e: > > On Wed, Jun 7, 2023 at 1:05=E2=80=AFAM Roger Sayle wrote: > > > > > > This patch addresses the last remaining issue with PR target/31985, tha= t > > GCC could make better use of memory addressing modes when implementing > > double word addition. This is achieved by adding a define_insn_and_spl= it > > 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. > > Yes, the approach looks good to me. But please take care not to > interfere with STV transformations. Hm, I have one second thought: +(define_insn_and_split "*add3_doubleword_concat" + [(set (match_operand: 0 "register_operand" "=3Dr") + (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]) =3D=3D * 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= ]);") The register allocator considers the instruction-to-be-split as one instruction, so it can allocate output register to match an input register (or a register that forms an input address), So, you have to either add an early clobber to the output, or somehow prevent output to clobber registers in the second pattern. Uros. > > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > > and make -k check, both with and without --target_board=3Dunix{-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. > > OK. > > Thanks, > Uros. > > > > > > > Roger > > -- > >