From patchwork Mon Jul 5 21:26:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1500957 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yJ5xOuKj; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GJf0R2MtMz9sX1 for ; Tue, 6 Jul 2021 07:27:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0C88383A836 for ; Mon, 5 Jul 2021 21:27:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0C88383A836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1625520434; bh=zfMKifAjrNC6HZb+LeZOOE6bLikwe249FJTcktgzSl0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yJ5xOuKjhCVOD6SvwAeAWsVSi2AbmQr5785V/Ya+SQO7ul9IpLhmEbUMRoHsTGLIp h+3HwYRLU9HiRruw6Ca5FJZMt/4mEsxnZz/NI0wJss6sKmoqNjFa8KUMqtcdEilxDE QoYeLtmOBf4RgCnQLRNhWurmRCriNVjMW23lndfE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 4A0113850409 for ; Mon, 5 Jul 2021 21:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A0113850409 Received: by mail-ot1-x336.google.com with SMTP id o17-20020a9d76510000b02903eabfc221a9so19623458otl.0 for ; Mon, 05 Jul 2021 14:26:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=zfMKifAjrNC6HZb+LeZOOE6bLikwe249FJTcktgzSl0=; b=jSnKcoufhZxZmyrorHRP8l25ci8IKHUo8EdCoVAUcwOiGm9a0kkJRs34eJPWJ+fW3z uiPvxh3GUrcpAnqZ39fl828mNvzJoUfuAkP8bk9uVfpzlagbXEMYE6IsxPX9mCPFxYWP XCHaFLY9yyYpiyfS/633h/qMhwAtWW8rFW/yWEb5XO+GlGDQnkjasJuXVXcyKkxplu5o uqUVKUfgzVru8kbf1dEIK68psM59YDH48yGwwyflxetonR38mXefztmz1fJa4omOfCqS GsA4no5Bwh1fy9oPbbP45ovh945QnMctHM5o0ofdFZSD/ElwdEjoQLUdmS1I4zXt6zyE l4DQ== X-Gm-Message-State: AOAM533QC+fBAeinAVTfeblAurofM3lG+vG+U8Dvg0mBZi77mIUnxebk geM3i6iqY+3uLwZgyiXrohKisivJXHVA+w== X-Google-Smtp-Source: ABdhPJynLSPdZS/wNuG5GBMcLCnRQzNIRMA4ME9BiGzAb+3e5mhGjDh4XH7M9VNJ9Exd3Jkg1Nj6Kg== X-Received: by 2002:a9d:6d17:: with SMTP id o23mr12162464otp.13.1625520389429; Mon, 05 Jul 2021 14:26:29 -0700 (PDT) Received: from [192.168.1.17] (c-98-202-48-222.hsd1.ut.comcast.net. [98.202.48.222]) by smtp.gmail.com with ESMTPSA id 37sm348133otq.72.2021.07.05.14.26.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Jul 2021 14:26:28 -0700 (PDT) To: GCC Patches Subject: [committed] Remove redundant compare in shift loop on H8 Message-ID: <863a1d0a-9712-0b2e-37a5-8d4ac50d8c79@gmail.com> Date: Mon, 5 Jul 2021 15:26:27 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" As I've mentioned elsewhere, the H8, particularly early models has very limited shift capabilities -- including no inherent support for shift by a variable amount. Naturally GCC accommodates this by emitting a suitable loop. The shift loop has a typical sequence.  Shift, decrement counter, test counter, branch to top of loop if counter hasn't reached zero.  These are emitted as RTL fairly late in the pipeline (after prologue/epilogue generation).   Prior to removal of cc0 the existing machinery was capable of removing the test of the counter and instead relying on the condition codes set by the decrement. Because this expansion happens so late (after cmpelim) we were failing to remove the unnecessary test.  My first attempt moved the expansion to a slightly earlier point, but the point where we want it doesn't necessarily have register lifetime information, which the patterns will try to exploit to generate better code. This is a slightly different approach.  It leaves the expansion where it is, but generates condition code aware RTL.  So the expansion has the shift, decrement counter & update condition codes, branch to top of loop if counter hasn't reached zero.  ie, it natively handles the condition codes. This eliminates one cmp insn in every shift-by-variable-amount loop. Committed to the trunk after the usual testing. Jeff commit 1562c7987be115311a75b1074c3768a1b006adb6 Author: Jeff Law Date: Mon Jul 5 17:23:43 2021 -0400 Remove redundant compare in shift loop on H8 gcc/ChangeLog * config/h8300/shiftrotate.md (shift-by-variable patterns): Update to generate condition code aware RTL directly. diff --git a/gcc/config/h8300/shiftrotate.md b/gcc/config/h8300/shiftrotate.md index 0476324bf22..485303cb906 100644 --- a/gcc/config/h8300/shiftrotate.md +++ b/gcc/config/h8300/shiftrotate.md @@ -385,10 +385,15 @@ (parallel [(set (match_dup 0) (match_op_dup 2 [(match_dup 0) (const_int 1)])) - (clobber (scratch:QI))]) - (set (match_dup 1) (plus:QI (match_dup 1) (const_int -1))) + (clobber (reg:CC CC_REG))]) + (parallel + [(set (reg:CCZN CC_REG) + (compare:CCZN + (plus:QI (match_dup 1) (const_int -1)) + (const_int 0))) + (set (match_dup 1) (plus:QI (match_dup 1) (const_int -1)))]) (set (pc) - (if_then_else (ne (match_dup 1) (const_int 0)) + (if_then_else (ne (reg:CCZN CC_REG) (const_int 0)) (label_ref (match_dup 4)) (pc))) (match_dup 5)] @@ -416,10 +421,15 @@ (parallel [(set (match_dup 0) (match_op_dup 2 [(match_dup 0) (const_int 1)])) - (clobber (scratch:QI))]) - (set (match_dup 3) (plus:QI (match_dup 3) (const_int -1))) + (clobber (reg:CC CC_REG))]) + (parallel + [(set (reg:CCZN CC_REG) + (compare:CCZN + (plus:QI (match_dup 3) (const_int -1)) + (const_int 0))) + (set (match_dup 3) (plus:QI (match_dup 3) (const_int -1)))]) (set (pc) - (if_then_else (ne (match_dup 3) (const_int 0)) + (if_then_else (ne (reg:CCZN CC_REG) (const_int 0)) (label_ref (match_dup 4)) (pc))) (match_dup 5)]