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 423F13857433 for ; Mon, 4 Jul 2022 18:51:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 423F13857433 Received: by mail-qk1-x72d.google.com with SMTP id z16so7287410qkj.7 for ; Mon, 04 Jul 2022 11:51:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=xs++lv90rPOiqx9IQUJ8NFJ0xH2cfcMSWLT8kQLhxSg=; b=7P2Bt5o/Jcs5N4GBHR7Jr8g1czVvj8UU/Jny68Bx4QRnGWjZOy2YZVceLIkXvQqTBa Tpv4PUNFCjBr/T6DZjytVDq1PganJ8qBp78JUqp+EGH/Vvwrdbkf6BI4HuX3LC9tZwEI PqxlXmeMiOxOflUZgbOPC4zPh5J2MXgMkhmdgRD+8YD/VNYefQ+61s3LiTJqUFOOJqgV DVuEntV2/H+O9lLkmCMQqS1OAqO8jVF7OQFSXnIy8DAcu9rfZ5QfpQPeHXtEDhGcWJfA Y67EeTONOoA8UgoUqgqhEc8qG5hpzNFzBIu/AJDoweC17YKLVdLOWdzHUNqfF8Cxedtc ePYQ== X-Gm-Message-State: AJIora+sc7vldrFozjRXQTAjuNy3Gmu11vGaLHH2x0XFipG9l1kG9uLJ BgioGIAAOPBMZup4WeCBMC21+3283N6GFVLH1Cgw76ggWeY= X-Google-Smtp-Source: AGRyM1saEXk7rSJBTH+rLr+wg1Ck1hc1ybg2phlCgJfPDSWUP4Z8ulKZFARPztWUndQ9X17IkWgupZHv/NMY0nP1cwY= X-Received: by 2002:a05:620a:1a28:b0:6b1:4d4d:c7c3 with SMTP id bk40-20020a05620a1a2800b006b14d4dc7c3mr20148857qkb.522.1656960717568; Mon, 04 Jul 2022 11:51:57 -0700 (PDT) MIME-Version: 1.0 References: <025701d88954$f281ca40$d7855ec0$@nextmovesoftware.com> <007501d88fcb$56f15820$04d40860$@nextmovesoftware.com> In-Reply-To: <007501d88fcb$56f15820$04d40860$@nextmovesoftware.com> From: Uros Bizjak Date: Mon, 4 Jul 2022 20:51:46 +0200 Message-ID: Subject: Re: [x86 PATCH] PR rtl-optimization/96692: ((A|B)^C)^A using andn with -mbmi. 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.4 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 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: , X-List-Received-Date: Mon, 04 Jul 2022 18:52:00 -0000 On Mon, Jul 4, 2022 at 7:27 PM Roger Sayle wro= te: > > > Hi Uros, > Thanks for the review. This patch implements all of your suggestions, bo= th > removing ix86_pre_reload_split from the combine splitter(s), and dividing > the original splitter up into four simpler variants, that use match_dup t= o > handle the variants/permutations caused by operator commutativity. > > This revised patch has been tested on x86_64-pc-linux-gnu with make boots= trap > and make -k check, both with and without --target_board=3Dunix{-m32} with= no > new failures. Ok for mainline? > > 2022-07-04 Roger Sayle > Uro=C5=A1 Bizjak > > gcc/ChangeLog > PR rtl-optimization/96692 > * config/i386/i386.md (define_split): Split ((A | B) ^ C) ^ D > as (X & ~Y) ^ Z on target BMI when either C or D is A or B. > > gcc/testsuite/ChangeLog > PR rtl-optimization/96692 > * gcc.target/i386/bmi-andn-4.c: New test case. OK. Thanks, Uros. > > Thanks again, > Roger > -- > > > -----Original Message----- > > From: Uros Bizjak > > Sent: 26 June 2022 18:08 > > To: Roger Sayle > > Cc: gcc-patches@gcc.gnu.org > > Subject: Re: [x86 PATCH] PR rtl-optimization/96692: ((A|B)^C)^A using a= ndn with > > -mbmi. > > > > On Sun, Jun 26, 2022 at 2:04 PM Roger Sayle > > wrote: > > > > > > > > > This patch addresses PR rtl-optimization/96692 on x86_64, by providin= g > > > a define_split for combine to convert the three operation ((A|B)^C)^D > > > into a two operation sequence using andn when either A or B is the > > > same register as C or D. This is essentially a reassociation problem > > > that's only a win if the target supports an and-not instruction (as w= ith -mbmi). > > > > > > Hence for the new test case: > > > > > > int f(int a, int b, int c) > > > { > > > return (a ^ b) ^ (a | c); > > > } > > > > > > GCC on x86_64-pc-linux-gnu wth -O2 -mbmi would previously generate: > > > > > > xorl %edi, %esi > > > orl %edx, %edi > > > movl %esi, %eax > > > xorl %edi, %eax > > > ret > > > > > > but with this patch now generates: > > > > > > andn %edx, %edi, %eax > > > xorl %esi, %eax > > > ret > > > > > > I'll investigate whether this optimization can also be implemented > > > more generically in simplify_rtx when the backend provides accurate > > > rtx_costs for "(and (not ..." (as there's no optab for andn). > > > > > > 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? > > > > > > > > > 2022-06-26 Roger Sayle > > > > > > gcc/ChangeLog > > > PR rtl-optimization/96692 > > > * config/i386/i386.md (define_split): Split ((A | B) ^ C) ^ D > > > as (X & ~Y) ^ Z on target BMI when either C or D is A or B. > > > > > > gcc/testsuite/ChangeLog > > > PR rtl-optimization/96692 > > > * gcc.target/i386/bmi-andn-4.c: New test case. > > > > + "TARGET_BMI > > + && ix86_pre_reload_split () > > + && (rtx_equal_p (operands[1], operands[3]) > > + || rtx_equal_p (operands[1], operands[4]) > > + || (REG_P (operands[2]) > > + && (rtx_equal_p (operands[2], operands[3]) > > + || rtx_equal_p (operands[2], operands[4]))))" > > > > You don't need a ix86_pre_reload_split for combine splitter* > > > > OTOH, please split the pattern to two for each commutative operand and = use > > (match_dup x) instead. Something similar to [1]. > > > > *combine splitter is described in the documentation as the splitter pat= tern that > > does *not* match any existing insn pattern. > > > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596804.html > > > > Uros.