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: 349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2913121pxt; Tue, 2 Aug 2022 04:32:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQC9btThut1+sUUm+3sBvGsq9NQLFrl7diUs3feqqzuoQDQiSOxbXZn7L8tjpKFh1g3Dfd X-Received: by 2002:a17:907:a0c7:b0:72f:b205:112 with SMTP id hw7-20020a170907a0c700b0072fb2050112mr15674761ejc.559.1659439939826; Tue, 02 Aug 2022 04:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659439939; cv=none; d=google.com; s=arc-20160816; b=X2Dy5l6t8p++kOIrugyKfYxG7B0gLuaY30boMRPwNdudKGyICgABOoYP5pTfW28aDg i3tWLRSsoA797RmxHoqYGUg/Ah6LLfUW8YMoy/I9K+9l8BZ23iJ51PUT3Iyb0Ggso7Pw e3HDPReboRGJH4l0V/dKab0paUskGGyhCgLI3Nw1av6FNaRl8sm4fC2/hrYCymSbFc5q knlPJbcVoBr3NaMHQ9GYXI5YACCVEkUyXEhkjb09uvwC10cgACtboRp4TjUo/wYoTePV 6v2UljYFEEQO0JV/lSpc3gFAcZGvzpz8FfjKADNoakfB4a8MbfznnTtbXtRXijqKDpDA qkLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=y1NB/EVnJjXnFwO3qPVfhH0+Z/3CIb4iMHlU+Iqls/Y=; b=GxZj3tiA6SVZmzHho0b62zYW5EFUT6cVKuAiQqqIsnDIJlJ3uuTH4hbWT2nrfy9QJY G4lC9Q5RP20m5bcu8leqsvOP9GIDD1OjLPpvzGDErMaG97TUpkRALoVGAcFZpv6PTbTl /ceMn1/YmIpdUMIqpcqcgUNocWoWSySPN/XKih8iM2mzW21qilQSKcHcX7y1RloW5YNe w4AjfG0yARc7GV7HdXuhvH/MCAvbt97M5aEf1KAPZxDblhXREfMGLDCZfyMlD1lSPMoH 8soNWHq1GGcS1IuT/roVYGd0hF9dojBwSd09rCM4b/LrCoEs0yaouYub0d78ImuXGX4p iz0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=Y7APe3c2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i7-20020a056402054700b0043d373fd120si1215717edx.47.2022.08.02.04.32.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 04:32:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=Y7APe3c2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4872384B07C for ; Tue, 2 Aug 2022 11:32:04 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740048894467016751?= X-GMAIL-MSGID: =?utf-8?q?1740048894467016751?= 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)