From patchwork Fri Jun 18 22:06:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1494458 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=luKifCVi; 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 4G6ChB36Vgz9sSn for ; Sat, 19 Jun 2021 08:07:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6957939B5038 for ; Fri, 18 Jun 2021 22:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6957939B5038 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624054023; bh=E6C2TDOy3w0I96oCUokWw7KuvC9bclOkg22WZDDlxMM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=luKifCViJp9WAG7fgOcdDUIzHyqARbvIZ+tf2iupdpt5UPpgSbkYpJZTu+o1JMC+X KAgWtebOvClofw6xn5YF1T3x5xrED0MzyjEomJ7Ga4Nr0pN093ionuiC9S/ICdsEKf twmsJUm21eKdY2EdmJov3gCxGQjr4+3OO0r0MA4Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id AB58939B5014 for ; Fri, 18 Jun 2021 22:06:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AB58939B5014 Received: by mail-pg1-x535.google.com with SMTP id g22so8972207pgk.1 for ; Fri, 18 Jun 2021 15:06:08 -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=E6C2TDOy3w0I96oCUokWw7KuvC9bclOkg22WZDDlxMM=; b=d7TzXGL/ZNEoKvefgsjPs3D1Am5lgoaQeImmqpdk5z0Sqy9BOrZEXdHG8t1F7lLuZu Jy/HMOyxBA5kl6t3nHoMDfi14GilFFkyEnV1ITOVYVaKzG61Ge3grpwYKiAd2wuxj3Xk aK8wgHLIsbIqxLcskw79LlZMsSf7hcdbD9ke0mvY4vnHw84gilqQzj0Oqn3QU2Ty9BTf I7tzMlhRLIEDvlWcqJR0aGkn1IWyCmSJEeC6+0r/8wMsrXJzGeMR0/Fc3qlLrriAuO8H emTlUKJcm0ISRipFxPSvNKizcrDHHYz4NAsWXzLXpk6S2n9M0ZHKtGxn6bc4a2qR3qXv zTmw== X-Gm-Message-State: AOAM533EUkbZDaNEeZL9yeHGDwvkDzu08D+CJBifCFJliYEad7S6s2bO imskX12NQOZ6fSnEtF0gG9kGgLVezhibcA== X-Google-Smtp-Source: ABdhPJwTbbLepGuIZRGUBa5rM09BdYtzilMC5/tSlHUt144qPuAgqSmxV52zHhZYvCsMEwSaFGoAZQ== X-Received: by 2002:a63:180c:: with SMTP id y12mr12344243pgl.180.1624053967332; Fri, 18 Jun 2021 15:06:07 -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 s11sm11924198pjz.42.2021.06.18.15.06.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Jun 2021 15:06:06 -0700 (PDT) To: GCC Patches Subject: [committed] More useless code elimination on the H8 Message-ID: Date: Fri, 18 Jun 2021 16:06:05 -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=-7.9 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.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" Two minor improvements on the H8 today. First, the source operand of a SET could be a SYMBOL_REF.  That's valid for setting condition codes.  I'm guessing its primarily valuable when testing for weak symbols.  Either way, adding support for that in select_cc_mode allows the compiler to remove a few more comparisons. Second, the H8 does not expose DImode operations, so generic parts of the compiler will arrange to synthesize DImode operations from SImode operations.  This is fine and good.  However, doing so does tend to generate some useless code.  For example (and:DI (reg:DI) (const_int 0xffffffff00000000) when synthesized via SImode operations generates an AND against -1 for the upper word which should simplify into a trivial copy. But on the H8 we do not have SImode and DImode tieable.  So the costing model falls apart a bit and CSE thinks it's better to just leave things alone.  This patch adds a bit of smarts to the logical expander to avoid creating the obviously useless logical ops.  Note we don't have to handle everything here.  If the RHS would simplify to a constant, CSE would do the right thing.   So we just want to handle cases where the RHS is going to simplify into a simple register operand.  And in practice I've only seen this fire for AND.  Anyway, the twiddle to the expander eliminates a few more instructions, particularly in libgcc. Anyway, these have both run through my tester and I'm committing this to the trunk. Jeff commit 629cbc682a773e64c4bcb800ea98fb3051cd810c Author: Jeff Law Date: Fri Jun 18 18:02:16 2021 -0400 [committed] More useless code elimination on the H8 gcc/ * config/h8300/h8300.c (h8300_select_cc_mode): Handle SYMBOL_REF. * config/h8300/logical.md (3 logcial expander): Generate more efficient code when the source can be trivially simplified. diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c index 1077a2b6ae0..2b88325d2f7 100644 --- a/gcc/config/h8300/h8300.c +++ b/gcc/config/h8300/h8300.c @@ -1950,7 +1950,7 @@ h8300_select_cc_mode (enum rtx_code cond, rtx op0, rtx op1) || GET_CODE (op0) == NEG || GET_CODE (op0) == AND || GET_CODE (op0) == IOR || GET_CODE (op0) == XOR || GET_CODE (op0) == NOT || GET_CODE (op0) == ASHIFT - || GET_CODE (op0) == MULT + || GET_CODE (op0) == MULT || GET_CODE (op0) == SYMBOL_REF || GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND || REG_P (op0) || MEM_P (op0))) return CCZNmode; diff --git a/gcc/config/h8300/logical.md b/gcc/config/h8300/logical.md index cb4c6384bdf..07d36cf0ef4 100644 --- a/gcc/config/h8300/logical.md +++ b/gcc/config/h8300/logical.md @@ -4,7 +4,27 @@ (logicals:QHSI (match_operand:QHSI 1 "register_operand" "") (match_operand:QHSI 2 "h8300_src_operand" "")))] "" - "") + " + { + enum machine_mode mode = GET_MODE (operands[0]); + /* DImodes are not considered tieable, as a result operations involving + subregs of DImode objects are considered expensive which can prevent + CSE from doing obvious simplifications. + + We may ultimately change what is tieable, but this is an immediate + workaround while we evaluate changes to tieable modes. + + The key in terms of what we want to handle is then the result of + the operation is not a constant. */ + if (( == AND && operands[2] == CONSTM1_RTX (mode)) + || ( == IOR && operands[2] == CONST0_RTX (mode)) + || ( == XOR && operands[2] == CONST0_RTX (mode)) + || (( == AND || == IOR) && operands[1] == operands[2])) + { + emit_move_insn (operands[0], operands[1]); + DONE; + } + }") ;; There's a ton of cleanup to do from here below. ;; ----------------------------------------------------------------------