From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by sourceware.org (Postfix) with ESMTPS id CB2783858C56 for ; Sun, 26 Jun 2022 17:07:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB2783858C56 Received: by mail-qk1-x736.google.com with SMTP id r138so5412255qke.13 for ; Sun, 26 Jun 2022 10:07:46 -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; bh=4m4TqZYJJyVJSHVNEflsFoCQ/W2qz9Z8hqQhiZeoE7M=; b=cfjH+isiXRwd8+uIQcnhUULmCcqCKzCNLpeg5Uw4wfkMaRtvoMlleakcMe2jdiYV5o rrRWBDAbNnvAY2hHoYfjCGT2CCfsW9wY5qItTxb2mrOHQzuEmJxhgnfTCAgZgc9/ooYe DAZEMhh96J+Tl6SZmLQu1AusRMgQwnlvG3EwTRdmAKYG8hjpQuON/4pJLgaVMhJ6Gz8L FIRmWOO4sMv0GdUQYEGCZVwe4YOfN2cIElKK4chWxP0bNUHSmkh+qj7QKrYMAb/W0DXi W5KGBUOYJ8jn+TZCUEmSuymalK8I5HSB3AtcRn9Bsn/SY/YvO99BOs1T6pwDH5RajY+i dTCg== X-Gm-Message-State: AJIora+rvY+Z7j5GcZ1axAIQkT5hv4DOtFD+mCJNoTWTxIRQBQ1axpCk vr3mqUjkfpH6PLoYc1u1Ok3gOGvSw8dfr8c/eBQ= X-Google-Smtp-Source: AGRyM1v+78CXj7s2FhuhXyjuUSBuj1yXBG0ij++DxmqSH+lZOnWa5yLhTG56bDxqhQk2Es8NVvS2Lii8LtI2I5EPCvc= X-Received: by 2002:a05:620a:2587:b0:6a7:ee6f:bf2a with SMTP id x7-20020a05620a258700b006a7ee6fbf2amr5972221qko.542.1656263266231; Sun, 26 Jun 2022 10:07:46 -0700 (PDT) MIME-Version: 1.0 References: <025701d88954$f281ca40$d7855ec0$@nextmovesoftware.com> In-Reply-To: <025701d88954$f281ca40$d7855ec0$@nextmovesoftware.com> From: Uros Bizjak Date: Sun, 26 Jun 2022 19:07:35 +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" X-Spam-Status: No, score=-2.2 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: Sun, 26 Jun 2022 17:07:48 -0000 On Sun, Jun 26, 2022 at 2:04 PM Roger Sayle wrote: > > > This patch addresses PR rtl-optimization/96692 on x86_64, by providing > 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 with -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=unix{-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 pattern that does *not* match any existing insn pattern. [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596804.html Uros.