From patchwork Fri Dec 16 13:33:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 62004 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38172383FD6C for ; Fri, 16 Dec 2022 13:34:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38172383FD6C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671197662; bh=Y4WX7LhnUDB73m3m3iv07zy4PcH5Rm1bCU8lmSnIEqg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=g02fYoZ9ZDIToPznyRtCKbdlDSWHWXeGyA63r24FV3Xw8HThUDMjbFUpZ0hZXVlZL gk2c+HG02l/moR6jO8VIBtLCtTdbuX9Xw3nMvKdqomFfY38k79lEotRGRN1/XwZIYG koAwh+NcCgU/3qY6PuE6zGFhqhV280FZIP44Mlto= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 73CB9383EB10 for ; Fri, 16 Dec 2022 13:33:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73CB9383EB10 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6B60734131 for ; Fri, 16 Dec 2022 13:33:53 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 671502C141 for ; Fri, 16 Dec 2022 13:33:53 +0000 (UTC) Date: Fri, 16 Dec 2022 13:33:53 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Simplify gimple_assign_load User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20221216133422.38172383FD6C@sourceware.org> The following simplifies and outlines gimple_assign_load. In particular it is not necessary to get at the base of the possibly loaded expression but just handle the case of a single handled component wrapping a non-memory operand. Bootstrapped and tested on x86_64-unknown-linux-gnu, not yet sure if I queue this for stage1 or push it next week. * gimple.h (gimple_assign_load): Outline... * gimple.cc (gimple_assign_load): ... here. Avoid get_base_address and instead just strip the outermost handled component, treating a remaining handled component as load. --- gcc/gimple.cc | 20 ++++++++++++++++++++ gcc/gimple.h | 17 +---------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gcc/gimple.cc b/gcc/gimple.cc index dd054e16453..e7bb7dd12f6 100644 --- a/gcc/gimple.cc +++ b/gcc/gimple.cc @@ -1797,6 +1797,26 @@ gimple_assign_unary_nop_p (gimple *gs) == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs))))); } +/* Return true if GS is an assignment that loads from its rhs1. */ + +bool +gimple_assign_load_p (const gimple *gs) +{ + tree rhs; + if (!gimple_assign_single_p (gs)) + return false; + rhs = gimple_assign_rhs1 (gs); + if (TREE_CODE (rhs) == WITH_SIZE_EXPR) + return true; + if (handled_component_p (rhs)) + rhs = TREE_OPERAND (rhs, 0); + return (handled_component_p (rhs) + || DECL_P (rhs) + || TREE_CODE (rhs) == MEM_REF + || TREE_CODE (rhs) == TARGET_MEM_REF); +} + + /* Set BB to be the basic block holding G. */ void diff --git a/gcc/gimple.h b/gcc/gimple.h index adbeb063186..b6ece9f409b 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1629,6 +1629,7 @@ tree gimple_call_nonnull_arg (gcall *); bool gimple_assign_copy_p (gimple *); bool gimple_assign_ssa_name_copy_p (gimple *); bool gimple_assign_unary_nop_p (gimple *); +bool gimple_assign_load_p (const gimple *); void gimple_set_bb (gimple *, basic_block); void gimple_assign_set_rhs_from_tree (gimple_stmt_iterator *, tree); void gimple_assign_set_rhs_with_ops (gimple_stmt_iterator *, enum tree_code, @@ -2952,22 +2953,6 @@ gimple_store_p (const gimple *gs) return lhs && !is_gimple_reg (lhs); } -/* Return true if GS is an assignment that loads from its rhs1. */ - -static inline bool -gimple_assign_load_p (const gimple *gs) -{ - tree rhs; - if (!gimple_assign_single_p (gs)) - return false; - rhs = gimple_assign_rhs1 (gs); - if (TREE_CODE (rhs) == WITH_SIZE_EXPR) - return true; - rhs = get_base_address (rhs); - return (DECL_P (rhs) - || TREE_CODE (rhs) == MEM_REF || TREE_CODE (rhs) == TARGET_MEM_REF); -} - /* Return true if S is a type-cast assignment. */