From patchwork Sat Jul 8 13:04:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1805189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=u/acCN9f; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qyr8w12YLz20WT for ; Sat, 8 Jul 2023 23:05:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0666D3856DD6 for ; Sat, 8 Jul 2023 13:05:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0666D3856DD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688821517; bh=WfyRVsSBaOSp1RoI/bmJn0zs+bhRtPJkrhTW0Rw+3Vs=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=u/acCN9ftUFffP/TRgBGfdpdbbFLbIphQSa+C/7RWUlXu9jrzMOQ9K2Jm7WtrLQiu dsB5sdzQGN1NQYJiPD5DwHMR7qWc6i0gxDkxVOylHIBU1qBYjoOGjAsgGw0xnftQoD vclLnvQxV6NaWMw4ufed4yIWQsE908e9+SWXkmL4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id B43E43857718 for ; Sat, 8 Jul 2023 13:04:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B43E43857718 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-51cff235226so5436694a12.0 for ; Sat, 08 Jul 2023 06:04:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688821494; x=1691413494; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WfyRVsSBaOSp1RoI/bmJn0zs+bhRtPJkrhTW0Rw+3Vs=; b=erh6w2NcfXswBGEK7pn+8QGNbDSddGszqUN2mpTy+MG24ySwmq4oYPsK7wOfDMqYZ9 vWXjQIx66XUHhYNSxiZP1/ABfFK29cJA/TyNMSJp5lxSEjZeBtKshuXwHmV2ZA2K819v rOvjrRGjljdrNY4SwE40LM2vKN+p5+Ynct9u+Iobwc4PlmvR+GmL4IHl5BSskV+Ctezt OcWLbsTsQIGJEg3ndWVKlfAfraj1Wn+b7PFopBXT0OgP6kii3rfn+QiPvtrLqNs34Adt XK35Ydj+aA2YxXIem8EpbW4dyF/kA6kC0x4wMRX2QpowNJngOobvQjhOGLhnOrL95MsW 7uRw== X-Gm-Message-State: ABy/qLZkp4bbNJsVKd6XnqnPZSs0oVhAEdz0ibnF1RWobM2JNsh5bHxP 4p3vq0lLL05NYQr9/0oaNHot6Ba2zPSsbilEQwjeV2L2R/GUGTwS X-Google-Smtp-Source: APBJJlHalC37rkfssFgAFAkFbSfqHp1hxhJibZu+yh5pYd19SQx2ErF5BDdk0uRTo1daaWCivb3sPZBHccnzo6m7Ex4= X-Received: by 2002:a05:6402:2789:b0:51e:2e87:2416 with SMTP id b9-20020a056402278900b0051e2e872416mr7382644ede.5.1688821494111; Sat, 08 Jul 2023 06:04:54 -0700 (PDT) MIME-Version: 1.0 Date: Sat, 8 Jul 2023 15:04:43 +0200 Message-ID: Subject: [committed] cprop: Change return type of predicate functions from int to bool To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.3 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: Uros Bizjak via Gcc-patches From: Uros Bizjak Reply-To: Uros Bizjak Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Also change some internal variables from int to bool. gcc/ChangeLog: * cprop.cc (reg_available_p): Change return type from int to bool. (reg_not_set_p): Ditto. (try_replace_reg): Ditto. Change "success" variable to bool. (cprop_jump): Change return type from int to void and adjust function body accordingly. (constprop_register): Ditto. (cprop_insn): Ditto. Change "changed" variable to bool. (local_cprop_pass): Change return type from int to void and adjust function body accordingly. (bypass_block): Ditto. Change "change", "may_be_loop_header" and "removed_p" variables to bool. (bypass_conditional_jumps): Change return type from int to void and adjust function body accordingly. Change "changed" variable to bool. (one_cprop_pass): Ditto. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros. diff --git a/gcc/cprop.cc b/gcc/cprop.cc index 6ec0bda4a24..b7400c9a421 100644 --- a/gcc/cprop.cc +++ b/gcc/cprop.cc @@ -142,10 +142,10 @@ cprop_alloc (unsigned long size) return obstack_alloc (&cprop_obstack, size); } -/* Return nonzero if register X is unchanged from INSN to the end +/* Return true if register X is unchanged from INSN to the end of INSN's basic block. */ -static int +static bool reg_available_p (const_rtx x, const rtx_insn *insn ATTRIBUTE_UNUSED) { return ! REGNO_REG_SET_P (reg_set_bitmap, REGNO (x)); @@ -517,10 +517,10 @@ reset_opr_set_tables (void) CLEAR_REG_SET (reg_set_bitmap); } -/* Return nonzero if the register X has not been set yet [since the +/* Return true if the register X has not been set yet [since the start of the basic block containing INSN]. */ -static int +static bool reg_not_set_p (const_rtx x, const rtx_insn *insn ATTRIBUTE_UNUSED) { return ! REGNO_REG_SET_P (reg_set_bitmap, REGNO (x)); @@ -722,14 +722,14 @@ find_used_regs (rtx *xptr, void *data ATTRIBUTE_UNUSED) } /* Try to replace all uses of FROM in INSN with TO. - Return nonzero if successful. */ + Return true if successful. */ -static int +static bool try_replace_reg (rtx from, rtx to, rtx_insn *insn) { rtx note = find_reg_equal_equiv_note (insn); rtx src = 0; - int success = 0; + bool success = false; rtx set = single_set (insn); bool check_rtx_costs = true; @@ -765,7 +765,7 @@ try_replace_reg (rtx from, rtx to, rtx_insn *insn) if (num_changes_pending () && apply_change_group ()) - success = 1; + success = true; /* Try to simplify SET_SRC if we have substituted a constant. */ if (success && set && CONSTANT_P (to)) @@ -790,7 +790,7 @@ try_replace_reg (rtx from, rtx to, rtx_insn *insn) if (!rtx_equal_p (src, SET_SRC (set)) && validate_change (insn, &SET_SRC (set), src, 0)) - success = 1; + success = true; /* If we've failed perform the replacement, have a single SET to a REG destination and don't yet have a note, add a REG_EQUAL note @@ -808,7 +808,7 @@ try_replace_reg (rtx from, rtx to, rtx_insn *insn) if (!rtx_equal_p (dest, SET_DEST (set)) && validate_change (insn, &SET_DEST (set), dest, 0)) - success = 1; + success = true; } /* REG_EQUAL may get simplified into register. @@ -889,10 +889,10 @@ find_avail_set (int regno, rtx_insn *insn, struct cprop_expr *set_ret[2]) JUMP_INSNS. JUMP must be a conditional jump. If SETCC is non-NULL it is the instruction that immediately precedes JUMP, and must be a single SET of a register. FROM is what we will try to replace, - SRC is the constant we will try to substitute for it. Return nonzero + SRC is the constant we will try to substitute for it. Return true if a change was made. */ -static int +static bool cprop_jump (basic_block bb, rtx_insn *setcc, rtx_insn *jump, rtx from, rtx src) { rtx new_rtx, set_src, note_src; @@ -931,7 +931,7 @@ cprop_jump (basic_block bb, rtx_insn *setcc, rtx_insn *jump, rtx from, rtx src) /* If no simplification can be made, then try the next register. */ if (rtx_equal_p (new_rtx, SET_SRC (set))) - return 0; + return false; /* If this is now a no-op delete it, otherwise this must be a valid insn. */ if (new_rtx == pc_rtx) @@ -941,7 +941,7 @@ cprop_jump (basic_block bb, rtx_insn *setcc, rtx_insn *jump, rtx from, rtx src) /* Ensure the value computed inside the jump insn to be equivalent to one computed by setcc. */ if (setcc && modified_in_p (new_rtx, setcc)) - return 0; + return false; if (! validate_unshare_change (jump, &SET_SRC (set), new_rtx, 0)) { /* When (some) constants are not valid in a comparison, and there @@ -955,7 +955,7 @@ cprop_jump (basic_block bb, rtx_insn *setcc, rtx_insn *jump, rtx from, rtx src) if (!rtx_equal_p (new_rtx, note_src)) set_unique_reg_note (jump, REG_EQUAL, copy_rtx (new_rtx)); - return 0; + return false; } /* Remove REG_EQUAL note after simplification. */ @@ -992,14 +992,14 @@ cprop_jump (basic_block bb, rtx_insn *setcc, rtx_insn *jump, rtx from, rtx src) delete_insn (jump); } - return 1; + return true; } /* Subroutine of cprop_insn that tries to propagate constants. FROM is what we will try to replace, SRC is the constant we will try to substitute for it and INSN is the instruction where this will be happening. */ -static int +static bool constprop_register (rtx from, rtx src, rtx_insn *insn) { rtx sset; @@ -1016,12 +1016,12 @@ constprop_register (rtx from, rtx src, rtx_insn *insn) if (REG_P (dest) && cprop_jump (BLOCK_FOR_INSN (insn), insn, next_insn, from, src)) - return 1; + return true; } /* Handle normal insns next. */ if (NONJUMP_INSN_P (insn) && try_replace_reg (from, src, insn)) - return 1; + return true; /* Try to propagate a CONST_INT into a conditional jump. We're pretty specific about what we will handle in this @@ -1031,17 +1031,18 @@ constprop_register (rtx from, rtx src, rtx_insn *insn) (set (pc) (if_then_else ...)) */ else if (any_condjump_p (insn) && onlyjump_p (insn)) return cprop_jump (BLOCK_FOR_INSN (insn), NULL, insn, from, src); - return 0; + return false; } /* Perform constant and copy propagation on INSN. - Return nonzero if a change was made. */ + Return true if a change was made. */ -static int +static bool cprop_insn (rtx_insn *insn) { unsigned i; - int changed = 0, changed_this_round; + int changed_this_round; + bool changed = false; rtx note; do @@ -1079,7 +1080,8 @@ cprop_insn (rtx_insn *insn) if (src_cst && cprop_constant_p (src_cst) && constprop_register (reg_used, src_cst, insn)) { - changed_this_round = changed = 1; + changed = true; + changed_this_round = 1; global_const_prop_count++; if (dump_file != NULL) { @@ -1091,14 +1093,15 @@ cprop_insn (rtx_insn *insn) fprintf (dump_file, "\n"); } if (insn->deleted ()) - return 1; + return true; } /* Copy propagation. */ else if (src_reg && cprop_reg_p (src_reg) && REGNO (src_reg) != regno && try_replace_reg (reg_used, src_reg, insn)) { - changed_this_round = changed = 1; + changed = true; + changed_this_round = 1; global_copy_prop_count++; if (dump_file != NULL) { @@ -1121,7 +1124,7 @@ cprop_insn (rtx_insn *insn) while (changed_this_round); if (changed && DEBUG_INSN_P (insn)) - return 0; + return false; return changed; } @@ -1237,7 +1240,7 @@ do_local_cprop (rtx x, rtx_insn *insn) /* Do local const/copy propagation (i.e. within each basic block). */ -static int +static bool local_cprop_pass (void) { basic_block bb; @@ -1352,12 +1355,12 @@ implicit_set_cond_p (const_rtx cond) handle float, complex, and vector. If any subpart is a zero, then the optimization can't be performed. */ /* ??? The complex and vector checks are not implemented yet. We just - always return zero for them. */ + always return false for them. */ if (CONST_DOUBLE_AS_FLOAT_P (cst) && real_equal (CONST_DOUBLE_REAL_VALUE (cst), &dconst0)) - return 0; + return false; else - return 0; + return false; } return cprop_constant_p (cst); @@ -1510,21 +1513,21 @@ reg_killed_on_edge (const_rtx reg, const_edge e) basic block BB which has more than one predecessor. If not NULL, SETCC is the first instruction of BB, which is immediately followed by JUMP_INSN JUMP. Otherwise, SETCC is NULL, and JUMP is the first insn of BB. - Returns nonzero if a change was made. + Returns true if a change was made. During the jump bypassing pass, we may place copies of SETCC instructions on CFG edges. The following routine must be careful to pay attention to these inserted insns when performing its transformations. */ -static int +static bool bypass_block (basic_block bb, rtx_insn *setcc, rtx_insn *jump) { rtx_insn *insn; rtx note; edge e, edest; - int change; - int may_be_loop_header = false; - unsigned removed_p; + bool change; + bool may_be_loop_header = false; + bool removed_p; unsigned i; edge_iterator ei; @@ -1555,10 +1558,10 @@ bypass_block (basic_block bb, rtx_insn *setcc, rtx_insn *jump) } } - change = 0; + change = false; for (ei = ei_start (bb->preds); (e = ei_safe_edge (ei)); ) { - removed_p = 0; + removed_p = false; if (e->flags & EDGE_COMPLEX) { @@ -1663,8 +1666,8 @@ bypass_block (basic_block bb, rtx_insn *setcc, rtx_insn *jump) old_dest->index, e->src->index, e->src->index, old_dest->index, dest->index); } - change = 1; - removed_p = 1; + change = true; + removed_p = true; break; } } @@ -1681,22 +1684,22 @@ bypass_block (basic_block bb, rtx_insn *setcc, rtx_insn *jump) This function is now mis-named, because we also handle indirect jumps. */ -static int +static bool bypass_conditional_jumps (void) { basic_block bb; - int changed; + bool changed; rtx_insn *setcc; rtx_insn *insn; rtx dest; /* Note we start at block 1. */ if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)) - return 0; + return false; mark_dfs_back_edges (); - changed = 0; + changed = false; FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->next_bb, EXIT_BLOCK_PTR_FOR_FN (cfun), next_bb) { @@ -1724,7 +1727,8 @@ bypass_conditional_jumps (void) { if ((any_condjump_p (insn) || computed_jump_p (insn)) && onlyjump_p (insn)) - changed |= bypass_block (bb, setcc, insn); + if (bypass_block (bb, setcc, insn)) + changed = true; break; } else if (INSN_P (insn)) @@ -1742,16 +1746,16 @@ bypass_conditional_jumps (void) /* Main function for the CPROP pass. */ -static int +static bool one_cprop_pass (void) { + bool changed = false; int i; - int changed = 0; /* Return if there's nothing to do, or it is too expensive. */ if (n_basic_blocks_for_fn (cfun) <= NUM_FIXED_BLOCKS + 1 || gcse_or_cprop_is_too_expensive (_ ("const/copy propagation disabled"))) - return 0; + return false; global_const_prop_count = local_const_prop_count = 0; global_copy_prop_count = local_copy_prop_count = 0; @@ -1772,7 +1776,9 @@ one_cprop_pass (void) FIXME: The global analysis would not get into infinite loops if it would use the DF solver (via df_simple_dataflow) instead of the solver implemented in this file. */ - changed |= local_cprop_pass (); + if (local_cprop_pass ()) + changed = true; + if (changed) delete_unreachable_blocks (); @@ -1783,7 +1789,8 @@ one_cprop_pass (void) changed something. ??? This could run earlier so that any uncovered implicit sets sets could be exploited in local_cprop_pass() also. Later. */ - changed |= find_implicit_sets (); + if (find_implicit_sets ()) + changed = true; /* If local_cprop_pass() or find_implicit_sets() changed something, run df_analyze() to bring all insn caches up-to-date, and to take @@ -1840,7 +1847,8 @@ one_cprop_pass (void) = (GET_CODE (PATTERN (insn)) == TRAP_IF && XEXP (PATTERN (insn), 0) == const1_rtx); - changed |= cprop_insn (insn); + if (cprop_insn (insn)) + changed = true; /* Keep track of everything modified by this insn. */ /* ??? Need to be careful w.r.t. mods done to INSN. @@ -1882,7 +1890,8 @@ one_cprop_pass (void) emit_barrier_after_bb (to_split); } - changed |= bypass_conditional_jumps (); + if (bypass_conditional_jumps ()) + changed = true; FREE_REG_SET (reg_set_bitmap); free_cprop_mem ();