From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 08AB93838205 for ; Thu, 26 May 2022 18:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 08AB93838205 Received: by mail-qk1-x730.google.com with SMTP id b200so2163287qkc.7 for ; Thu, 26 May 2022 11:59:29 -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=U6sgD91Mtl/HW3SBhmH9uHmsom7kWSR9aqWWuip96Xo=; b=mlF/+uUrw0GBl+TZYB4csJPabwOZgBdFazJHTEfnL+/esobDfv+KmrWy/DznlPT/ro RTMFZnzWuKGDAh9B+v6RFFV5gttvj0EQxNSHOzbOcXCawOvgbEPbYneNdVUkOQnKvYfW 4PzP+OyNo1AgjtE6nlMM7e9Zo+UEuieC5XdkidDOgiF1jeJkElx/uy4J50hBlBubmfs+ ZVDeNSikHXm/C9DSrGmmqJk4cygZBzhxdi0AG1PP5ChARA6tQpXaYy4d5r6JkOSLfZUx I88Vg9sQcIKdFs0YM4OBn0weZB6OlHPo+0+5ihLdQWeDyFfIq5UvBCVWY9/xOcc4oQji TlvA== X-Gm-Message-State: AOAM533qsUPugpn52M0N7/wCwJu1fl6F33oP3hfi1GlJJngOWgBEjqlG k3XJs96tQJXL+WKyvz3ugtZ+owvHff4j6TGRv7jBHFrhD4I= X-Google-Smtp-Source: ABdhPJxgI5p0oIscrvcljDUBELg0DlLEbeKWOd72Ic8uGMvWJi80MkrZbQlitxBf4UBls6BlQxUp+HgNvBO2FivWhtE= X-Received: by 2002:a37:660a:0:b0:6a3:4868:c730 with SMTP id a10-20020a37660a000000b006a34868c730mr22598380qkc.180.1653591568295; Thu, 26 May 2022 11:59:28 -0700 (PDT) MIME-Version: 1.0 References: <006301d87130$3747a240$a5d6e6c0$@nextmovesoftware.com> In-Reply-To: <006301d87130$3747a240$a5d6e6c0$@nextmovesoftware.com> From: Uros Bizjak Date: Thu, 26 May 2022 20:59:17 +0200 Message-ID: Subject: Re: [x86 PATCH] Pre-reload splitter to transform and; cmp into not; test. To: Roger Sayle Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.7 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: Thu, 26 May 2022 18:59:30 -0000 On Thu, May 26, 2022 at 8:41 PM Roger Sayle wrote: > > > A common idiom for testing if a specific set of bits is set in a value > is to use "(X & Y) == Y", which on x86 results in an AND followed by a > CMP. A slightly improved implementation is to instead use (~X & Y)==0, > that uses a NOT and a TEST (or ANDN where available); still two "fast" > instructions, but typically shorter especially if Y is an immediate > constant. Because the above transformation would require more gimple > statements in SSA, and may only be a win on targets with flags registers, > it isn't performed by the middle-end, instead leaving this choice to > the backend. > > As an example, here's the change in code generation for pr91400-1.c > [which now requires a tweak to its dg-final clauses]. > > Before: > movl __cpu_model+12(%rip), %eax > andl $68, %eax // 3 bytes > cmpl $68, %eax // 3 bytes > sete %al > ret > > After: > movl __cpu_model+12(%rip), %eax > notl %eax // 2 bytes > testb $68, %al // 2 bytes > sete %al > ret > > > 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-05-26 Roger Sayle > > gcc/ChangeLog > * config/i386/i386.md (*test_not): New define_insn_and_split > to split a combined "and;cmp" sequence into "not;test". > > gcc/testsuite/ChangeLog > * gcc.target/i386/pr91400-1.c: Update for improved code generation. > * gcc.target/i386/pr91400-2.c: Likewise. > * gcc.target/i386/testnot-1.c: New test case. > * gcc.target/i386/testnot-2.c: Likewise. OK. Thanks, Uros.