From patchwork Tue Aug 2 11:31:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1662956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=Y7APe3c2; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LxtB53XfYz9sCD for ; Tue, 2 Aug 2022 21:31:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAA7F384F018 for ; Tue, 2 Aug 2022 11:31:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 30045385357D for ; Tue, 2 Aug 2022 11:31:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 30045385357D 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=y1NB/EVnJjXnFwO3qPVfhH0+Z/3CIb4iMHlU+Iqls/Y=; b=Y7APe3c2S3ywYmIH21aUzlTzUZ WVA1Q1iCMdbgYo301X59kTJwoLp25T3ez5m1hOsEQ3OjLI9eqJeoSoYQN4NL/eolQjMZf/uDz74K7 BjIABfJ9JmF1A/ssu3CyB8+BJtJKdtgemATApeorLN4n4ps4bOgVK8SOQ79puAnat4+tau9lQD/sX k47MrX/YBmSZyJKvfpnl8q0Xzw9yycTB94VT8NqZkiOQHmW4sWhwZnNLTr1daw8hi8SVyAd6MQAO5 VZyMUcgFJ9lt5SPu7acD/GkkPjVpVZMUu1dMpXxwJjirOItvnNnDdrjvSGEGsGQNhraH0IM2qmRt9 T69wYXsQ==; Received: from host86-169-41-119.range86-169.btcentralplus.com ([86.169.41.119]:54273 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oIq7e-0002l5-9K; Tue, 02 Aug 2022 07:31:38 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [x86 PATCH] Improved pre-reload split of double word comparison against -1. Date: Tue, 2 Aug 2022 12:31:36 +0100 Message-ID: <01ad01d8a663$6e062820$4a127860$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdimYvMcd7wPdRtkR8a0s5+VBlXbMQ== 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.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch adds an extra optimization to *cmp_doubleword to improve the code generated for comparisons against -1. Hypothetically, if a comparison against -1 reached this splitter we'd currently generate code that looks like: notq %rdx ; 3 bytes notq %rax ; 3 bytes orq %rdx, %rax ; 3 bytes setne %al With this patch we would instead generate the superior: andq %rdx, %rax ; 3 bytes cmpq $-1, %rax ; 4 bytes setne %al which is both faster and smaller, and also what's currently generated thanks to the middle-end splitting double word comparisons against zero and minus one during RTL expansion. Should that change, this would become a missed-optimization regression, but this patch also (potentially) helps suitable comparisons created by CSE and combine. This patch has been tested on x86_64-pc-linux-gnu, on its own and in combination with a middle-end patch tweaking RTL expansion, both with and without --target-board=unix{-m32}, with no new failures. Ok for mainline? 2022-08-02 Roger Sayle gcc/ChangeLog * config/i386/i386.md (*cmp_doubleword): Add a special case to split comparisons against -1 using AND and CMP -1 instructions. Thanks again, Roger diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index f1158e1..e8f3851 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -1526,6 +1526,15 @@ operands[i] = force_reg (mode, operands[i]); operands[4] = gen_reg_rtx (mode); + + /* Special case comparisons against -1. */ + if (operands[1] == constm1_rtx && operands[3] == constm1_rtx) + { + emit_insn (gen_and3 (operands[4], operands[0], operands[2])); + emit_insn (gen_cmp_1 (mode, operands[4], constm1_rtx)); + DONE; + } + if (operands[1] == const0_rtx) emit_move_insn (operands[4], operands[0]); else if (operands[0] == const0_rtx)