From patchwork Sun Jun 13 15:21:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1491452 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=Jfu8R2fC; 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 4G2ywZ2JPvz9sWD for ; Mon, 14 Jun 2021 01:21:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C12E238515F2 for ; Sun, 13 Jun 2021 15:21:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C12E238515F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623597688; bh=Txy50nfguiWOK8BQ7DnBxRhJtWWYjkwBxfxb8kD4OPw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Jfu8R2fCpayf6EomNNKRmfQrwmkfJvuTMKzogP3tiHKcA9k/EfAaKkY/HeV2BKdSo zUUKSMrRW3IBBrCtcz4LraB6DbmXV+YxCSfXjZdrGBDT+v6lkZmn9708aKX+opoqAP ekmCFzM8DCJ/u3fs/oBNWJf6sMB8k4uo3kDrm09s= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id C9986385800A for ; Sun, 13 Jun 2021 15:21:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9986385800A Received: by mail-pj1-x1035.google.com with SMTP id mp5-20020a17090b1905b029016dd057935fso8586473pjb.5 for ; Sun, 13 Jun 2021 08:21:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:message-id:date:user-agent :mime-version:content-language; bh=Txy50nfguiWOK8BQ7DnBxRhJtWWYjkwBxfxb8kD4OPw=; b=aIsek/KzZYjvtrpSxF/IMHQrppKndeDmEjwT3A0RoBf28h1M61frrGuLllP7+VTgPt 6g4rAqVPkDh0IspeqMC26pCLtZSil65E9gfrOO6hvbb7hzpsPDhicO6AQR+ffeOig39p g7tQvMTpViMYECa4Bm6+4GD6emwuvglMZ2IGwGlBn2S4H6D2fFWh6agh3mrvwfZ4LFv3 SHKeYN4PJTgArqYI2KEzseTz6x3Di5SeC4DPN1xwnwPF3uLgACF2NA1Csgf80gbDC2KU qHKGxU4Issy36ySNsVwM53uy/+5wFdMY698qT8N7KSY1Ks18VndcZBQRw3CIErXl8Vso 2X6w== X-Gm-Message-State: AOAM531fSDEtVB+uXGGlmMYqXiDplcecIcs6GbPqQDfIo5JxA02a5Y3j VFvRNyAKFipwdwEqJIqxl3PchaXbbnJtAA== X-Google-Smtp-Source: ABdhPJwQPdSXaySrB3Bb4sPp3+iatyVL9gRT+cWI2B6zbn6AbYe7vrfjBT61lsNy+Ail5fbfU6oJwA== X-Received: by 2002:a17:902:9b8b:b029:ee:bb74:7d46 with SMTP id y11-20020a1709029b8bb02900eebb747d46mr12910014plp.65.1623597666554; Sun, 13 Jun 2021 08:21:06 -0700 (PDT) Received: from [172.31.0.175] (c-98-202-48-222.hsd1.ut.comcast.net. [98.202.48.222]) by smtp.gmail.com with ESMTPSA id k8sm9948961pfg.185.2021.06.13.08.21.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 13 Jun 2021 08:21:05 -0700 (PDT) To: GCC Patches Subject: [committed] More improvements to H8 logicals for test/compare elimination Message-ID: <8409053c-093e-49c1-5dc9-75ef1c56b235@gmail.com> Date: Sun, 13 Jun 2021 09:21:03 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-8.1 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 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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" Another round of redundant test/compare elimination on the H8. This improves our ability to use QImode logicals.  Part of the problem we needed to resolve here was that we support generating the b* instructions which do not set condition codes as well as the usual and, ior, xor. The approach taken was to bring the b* form into the define_insn_and_split and not split when the b* form can be used (they're only used when twiddling a single bit).  This seems to work reasonably well based on the code I've looked at -- it's consistently finding optimization opportunities resulting in notable decreases in the size of newlib/libgcc. This in turn allows us to have a nice generic qi pattern which handles all the QImode logicals in the obvious and simple way. This patch also adds support for the muls patterns generating condition codes.  I didn't find any real examples of this being used across newlib/libgcc, but it's trivial to do.  Note that mulu does not set condition codes, so while it may look inconsistent, it matches the hardware to the best of my knowledge. Committing to the trunk (after a 21hr test cycle), Jeff commit 8a7d54b1e10b8f4fba1358260ed2e7056ed23cbd Author: Jeff Law Date: Sun Jun 13 11:09:38 2021 -0400 [committed] More improvements to H8 logicals for test/compare elimination gcc/ * config/h8300/logical.md (qi3_1): New pattern. (andqi3_1): Removed. (qi3_1): Do not split for IOR/XOR a single bit. (H8/SX bit logicals): Split out from other patterns. * config/h8300/multiply.md (mulqihi3_const): Renamed from mulqihi3_const_clobber_flags. (mulqihi3, mulhisi3_const, mulhisi3): Similarly diff --git a/gcc/config/h8300/logical.md b/gcc/config/h8300/logical.md index fae3c7cd0c5..cb4c6384bdf 100644 --- a/gcc/config/h8300/logical.md +++ b/gcc/config/h8300/logical.md @@ -69,14 +69,6 @@ "" [(set_attr "length" "8,2")]) -(define_insn "*andqi3_1" - [(set (match_operand:QI 0 "register_operand" "=r") - (and:QI (match_operand:QI 1 "register_operand" "%0") - (match_operand:QI 2 "h8300_src_operand" "rn"))) - (clobber (reg:CC CC_REG))] - "" - "and %X2,%X0" - [(set_attr "length" "2")]) (define_insn_and_split "*andor3" [(set (match_operand:QHSI 0 "register_operand" "=r") @@ -179,27 +171,49 @@ (match_operand:QI 2 "h8300_src_operand" "Y2,rQi")))] "TARGET_H8300SX || register_operand (operands[0], QImode) || single_one_operand (operands[2], QImode)" - "#" - "&& reload_completed" + { return == IOR ? "bset\\t%V2,%R0" : "bnot\\t%V2,%R0"; } + "&& reload_completed && !single_one_operand (operands[2], QImode)" [(parallel [(set (match_dup 0) (ors:QI (match_dup 1) (match_dup 2))) - (clobber (reg:CC CC_REG))])]) + (clobber (reg:CC CC_REG))])] + "" + [(set_attr "length" "8")]) -(define_insn "qi3_1_clobber_flags" - [(set (match_operand:QI 0 "bit_operand" "=U,rQ") - (ors:QI (match_operand:QI 1 "bit_operand" "%0,0") - (match_operand:QI 2 "h8300_src_operand" "Y2,rQi"))) +(define_insn "*qi3_1" + [(set (match_operand:QI 0 "bit_operand" "=rQ") + (ors:QI (match_operand:QI 1 "bit_operand" "%0") + (match_operand:QI 2 "h8300_src_operand" "rQi"))) (clobber (reg:CC CC_REG))] - "TARGET_H8300SX || register_operand (operands[0], QImode) - || single_one_operand (operands[2], QImode)" - { - if (which_alternative == 0) - return == IOR ? "bset\\t%V2,%R0" : "bnot\\t%V2,%R0"; - else if (which_alternative == 1) - return == IOR ? "or\\t%X2,%X0" : "xor\\t%X2,%X0"; - gcc_unreachable (); + "TARGET_H8300SX" + { return == IOR ? "or\\t%X2,%X0" : "xor\\t%X2,%X0"; } + [(set_attr "length" "*") + (set_attr "length_table" "logicb")]) + +(define_insn "*qi3_1" + [(set (match_operand:QI 0 "register_operand" "=r") + (ors:QI (match_operand:QI 1 "register_operand" "%0") + (match_operand:QI 2 "h8300_src_operand" "ri"))) + (clobber (reg:CC CC_REG))] + "TARGET_H8300SX" + { return == IOR ? "or\\t%X2,%X0" : "xor\\t%X2,%X0"; } + [(set_attr "length" "*") + (set_attr "length_table" "logicb")]) + +(define_insn "*qi3_1" + [(set (match_operand:QI 0 "register_operand" "=r") + (logicals:QI (match_operand:QI 1 "register_operand" "%0") + (match_operand:QI 2 "h8300_src_operand" "rn"))) + (clobber (reg:CC CC_REG))] + "" + { + if ( == IOR) + return "or\\t%X2,%X0"; + else if ( == XOR) + return "xor\\t%X2,%X0"; + else if ( == AND) + return "and\\t%X2,%X0"; + gcc_unreachable (); } - [(set_attr "length" "8,*") - (set_attr "length_table" "*,logicb")]) + [(set_attr "length" "2")]) ;; ---------------------------------------------------------------------- ;; {AND,IOR,XOR}{HI3,SI3} PATTERNS diff --git a/gcc/config/h8300/multiply.md b/gcc/config/h8300/multiply.md index 1d56d4797a7..8b9328c1282 100644 --- a/gcc/config/h8300/multiply.md +++ b/gcc/config/h8300/multiply.md @@ -26,7 +26,7 @@ (mult:HI (sign_extend:HI (match_dup 1)) (match_dup 2))) (clobber (reg:CC CC_REG))])]) -(define_insn "*mulqihi3_const_clobber_flags" +(define_insn "*mulqihi3_const" [(set (match_operand:HI 0 "register_operand" "=r") (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0")) (match_operand:QI 2 "nibble_operand" "IP4>X"))) @@ -47,7 +47,7 @@ (sign_extend:HI (match_dup 2)))) (clobber (reg:CC CC_REG))])]) -(define_insn "*mulqihi3_clobber_flags" +(define_insn "*mulqihi3" [(set (match_operand:HI 0 "register_operand" "=r") (mult:HI (sign_extend:HI (match_operand:QI 1 "register_operand" "%0")) (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))) @@ -78,7 +78,7 @@ (mult:SI (sign_extend:SI (match_dup 1)) (match_dup 2))) (clobber (reg:CC CC_REG))])]) -(define_insn "*mulhisi3_const_clobber_flags" +(define_insn "*mulhisi3_const" [(set (match_operand:SI 0 "register_operand" "=r") (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0")) (match_operand:SI 2 "nibble_operand" "IP4>X"))) @@ -99,7 +99,7 @@ (sign_extend:SI (match_dup 2)))) (clobber (reg:CC CC_REG))])]) -(define_insn "*mulhisi3_clobber_flags" +(define_insn "*mulhisi3" [(set (match_operand:SI 0 "register_operand" "=r") (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "%0")) (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))