From patchwork Tue May 9 13:23:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 91598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2880025vqo; Tue, 9 May 2023 06:23:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5C3nWWtLOKwLRcTTakWB6aNELd4YLLTiPnTBQpnpVxJZFtirZIAIkHjZk/ZmV6zejZ7TOV X-Received: by 2002:aa7:da08:0:b0:506:8470:c323 with SMTP id r8-20020aa7da08000000b005068470c323mr10102761eds.24.1683638635706; Tue, 09 May 2023 06:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683638635; cv=none; d=google.com; s=arc-20160816; b=vE85FXVK76lluQw8VVzeASP+B/cOp3+GkVX9lyZaI7gWxJD31BOHewvNQ7dij9zuAN Vs6vbumws0Rwrw66osCxVdb5M018TPzMmF0Jx526wW/UanBh1SXarGXfw4zV4mjt5UVo ULOVZ0uLyRiGNhlWrKbTD/9as7AR9i9FeMKhI/hXAFQSf7luEXepzBynxFmArDzIyCMW B1+3LbWJGuS0kyjzltjo7zn1HRcKMHrjLpYbJ3WAUDMDcnFavHv+d8jbewQ7q7Hd0MOW Y+1PTTnoZ1eoUYJPdXBLpGrfeFO75FK2RDEMEYt5FzNWSFouVUc1OZhvugt3sHBDtgPl /7/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=UBaBNaFIUBHUBcyr7Tl7gSDrO/jNSq3uq1YOvANVbmE=; b=M+0ckQcXW5Z48MsFNt6OvpmiClYf0aryAtu6hfkHTmST7B01XJqpN+SzcFB0FHRlCM fZI2BIa/+mtVsUeziQoRR/I9PXoe8akaQQTRaSzWnTVJc47VagqbnpZA4kvdtdhiaCgR /uskVO3l59La5EkclaxpgyGMqFjI15N4NiPfEPNueBdPhS0+CLG+OkPX/8J5y0ZVVlkA psv6i5ByUzFs/odG1oGG6AAx57Lwzp5oDfwwdkfHXXkcmsD90F9bYNXlOwU12Jtzgo9p 0uW6o3Qt/Zz6+2Ni/H27DUFJ4je8uQ68jJtjYGygv4lA6Refk4JnTCph1MIHB8Z9S45d Y+bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bGbrxm+b; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b20-20020a056402139400b0050bc50e4968si1164294edv.447.2023.05.09.06.23.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 06:23:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bGbrxm+b; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A31E3858414 for ; Tue, 9 May 2023 13:23:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A31E3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683638634; bh=UBaBNaFIUBHUBcyr7Tl7gSDrO/jNSq3uq1YOvANVbmE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bGbrxm+b/t/9CbiU57c315aJOptpxo1UylC3ZpuDKFyAJXhuOI60gW5FaWTWxDqUM 3teHxoy4agE7f9xYtKrUSBxzXV1b0mgjvt6Xludr+usgYAWpqifE6o3zCGP4HUNziB Sna2ymHInzM+qNNeng98wIPWa39fgnLyrQTtNrbo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id D87BB3858D37 for ; Tue, 9 May 2023 13:23:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D87BB3858D37 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-76c5404464fso96623639f.3 for ; Tue, 09 May 2023 06:23:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683638589; x=1686230589; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UBaBNaFIUBHUBcyr7Tl7gSDrO/jNSq3uq1YOvANVbmE=; b=j+xTamQ712aQnbfQJVEqPGr86LuoeHTklg6i+wyWscf/sRE7tD60fCeVkDmqehylXI XPbOztq05AWlRkPdrxIx3EiTa8f8UgmrTC1ETowGFJ+CKPShyERFO1YQWuMnl8YArf9D AhxGY0jB1sFt2p4qm6Yk+xsEhVg+GjwW/yB26cucKf9p7MEyGCDqZBl3xTbSSCEliyEh LgdAkz/mGPvn/RXk8zVwa0vSZU/jJqWSJG3jHOv4E5EcalVDHxQlHA9nyVSWiAeN47xu M8TIMh0JWm889q2qMNOUnAffdwWrN7iEopFarMjCA491E6o7AOLatn5lOU4Zorb+pHbq kQ2g== X-Gm-Message-State: AC+VfDzs5zKyNYBFjYikdErdyGvzlhNle+LpUcip2xcfD5ZkE+S7c4G1 Dna/OCodiLBAiIBoJq5KgoNHd2JL5Ns= X-Received: by 2002:a92:da09:0:b0:329:5353:857a with SMTP id z9-20020a92da09000000b003295353857amr9540553ilm.27.1683638589165; Tue, 09 May 2023 06:23:09 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::99f? ([2601:681:8600:13d0::99f]) by smtp.gmail.com with ESMTPSA id x1-20020a5d9ac1000000b00760f535cd5asm2851404ion.10.2023.05.09.06.23.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 May 2023 06:23:08 -0700 (PDT) Message-ID: Date: Tue, 9 May 2023 07:23:07 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Content-Language: en-US Subject: [committed] Eliminate more comparisons on the H8 port To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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-Patchwork-Original-From: Jeff Law via Gcc-patches From: Jeff Law Reply-To: Jeff Law 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?1765423066408252059?= X-GMAIL-MSGID: =?utf-8?q?1765423066408252059?= This patch fixes a minor code quality issue I found while testing LRA on the H8. Specifically we have a peephole which converts a comparison of a memory location against zero into a load + comparison which is actually more efficient. This triggers when there are registers available at the right point during peephole2. If the load is not a mode dependent address we can actually do better by realizing the load itself sets the proper flags and eliminate the comparison. I may have expected this to happen when I wrote the original peephole2 -- but cmpelim runs before peephole2, so clearly if we want to eliminate the comparison we have to do it manually. Committed to the trunk, Jeff commit 204303c81e82ddd01e7dc5a5a63719d476f9043c Author: Jeff Law Date: Tue May 9 07:18:45 2023 -0600 Eliminate more comparisons on the H8 port This patch fixes a minor code quality issue I found while testing LRA on the H8. Specifically we have a peephole which converts a comparison of a memory location against zero into a load + comparison which is actually more efficient. This triggers when there are registers available at the right point during peephole2. If the load is not a mode dependent address we can actually do better by realizing the load itself sets the proper flags and eliminate the comparison. I may have expected this to happen when I wrote the original peephole2, but cmpelim runs before peephole2, so clearly if we want to eliminate the comparison we have to do it manually. gcc/ * config/h8300/testcompare.md: Add peephole2 which uses a memory load to set flags, thus eliminating a compare against zero. diff --git a/gcc/config/h8300/testcompare.md b/gcc/config/h8300/testcompare.md index 81dce1d0bc1..efa66d274c7 100644 --- a/gcc/config/h8300/testcompare.md +++ b/gcc/config/h8300/testcompare.md @@ -171,13 +171,25 @@ (define_insn "cmpsi" (set_attr "length_table" "*,add")]) ;; Convert a memory comparison to a move if there is a scratch register. +;; This is preferred over the next as we can proactively avoid the +;; comparison. +(define_peephole2 + [(match_scratch:QHSI 1 "r") + (set (reg:CC CC_REG) + (compare (match_operand:QHSI 0 "memory_operand" "") + (const_int 0)))] + "!mode_dependent_address_p (XEXP (operands[0], 0), MEM_ADDR_SPACE (operands[0]))" + [(parallel [(set (reg:CCZN CC_REG) (compare:CCZN (match_dup 0) (const_int 0))) + (set (match_dup 1) (match_dup 0))])]) +;; Similarly, but used when the memory reference is an autoinc address +;; mode. (define_peephole2 [(match_scratch:QHSI 1 "r") (set (reg:CC CC_REG) (compare (match_operand:QHSI 0 "memory_operand" "") (const_int 0)))] - "" + "mode_dependent_address_p (XEXP (operands[0], 0), MEM_ADDR_SPACE (operands[0]))" [(parallel [(set (match_dup 1) (match_dup 0)) (clobber (reg:CC CC_REG))]) (set (reg:CC CC_REG) (compare:CC (match_dup 1) (const_int 0)))])