From patchwork Mon Jun 19 07:47:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1796344 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=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=I584jHcF; dkim-atps=neutral Received: from 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 4Ql21C2pjwz20XQ for ; Mon, 19 Jun 2023 17:47:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56A3F385771C for ; Mon, 19 Jun 2023 07:47:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56A3F385771C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687160860; bh=iaTE9aid8BjFX/PI/7MOYmuB8iC5H7h4rvd2pVu7B2M=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=I584jHcF7kZPFOCcjzrKjgSaWkZclr3fRPzHhOklW3b/k8stncxCCKBpmrDmcfNeX 9L/F+ZiFsFlRQwgZW8Ev8OUMcMDxHKMd7xmsDY3wQP+OnbA5I/pKgCt8Q354DDIMLO fS4b5OPxmZwPbydEgmq95+kMn76puol9G/AQ3r+E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 9B7143858D3C for ; Mon, 19 Jun 2023 07:47:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B7143858D3C Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 2905928AEB9; Mon, 19 Jun 2023 09:47:18 +0200 (CEST) Date: Mon, 19 Jun 2023 09:47:18 +0200 To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Tiny phiprop compile time optimization Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch avoids unnecessary post dominator and update_ssa in phiprop. Bootstrapped/regtested x86_64-linux, OK? gcc/ChangeLog: * tree-ssa-phiprop.cc (propagate_with_phi): Add post_dominators_computed; compute post dominators lazilly. (const pass_data pass_data_phiprop): Remove TODO_update_ssa. (pass_phiprop::execute): Update; return TODO_update_ssa if something changed. diff --git a/gcc/tree-ssa-phiprop.cc b/gcc/tree-ssa-phiprop.cc index 3cb4900b6be..87e3a2ccf3a 100644 --- a/gcc/tree-ssa-phiprop.cc +++ b/gcc/tree-ssa-phiprop.cc @@ -260,7 +260,7 @@ chk_uses (tree, tree *idx, void *data) static bool propagate_with_phi (basic_block bb, gphi *phi, struct phiprop_d *phivn, - size_t n) + size_t n, bool *post_dominators_computed) { tree ptr = PHI_RESULT (phi); gimple *use_stmt; @@ -324,6 +324,12 @@ propagate_with_phi (basic_block bb, gphi *phi, struct phiprop_d *phivn, gimple *def_stmt; tree vuse; + if (!*post_dominators_computed) + { + calculate_dominance_info (CDI_POST_DOMINATORS); + *post_dominators_computed = true; + } + /* Only replace loads in blocks that post-dominate the PHI node. That makes sure we don't end up speculating loads. */ if (!dominated_by_p (CDI_POST_DOMINATORS, @@ -465,7 +471,7 @@ const pass_data pass_data_phiprop = 0, /* properties_provided */ 0, /* properties_destroyed */ 0, /* todo_flags_start */ - TODO_update_ssa, /* todo_flags_finish */ + 0, /* todo_flags_finish */ }; class pass_phiprop : public gimple_opt_pass @@ -490,9 +497,9 @@ pass_phiprop::execute (function *fun) gphi_iterator gsi; unsigned i; size_t n; + bool post_dominators_computed = false; calculate_dominance_info (CDI_DOMINATORS); - calculate_dominance_info (CDI_POST_DOMINATORS); n = num_ssa_names; phivn = XCNEWVEC (struct phiprop_d, n); @@ -508,7 +515,8 @@ pass_phiprop::execute (function *fun) if (bb_has_abnormal_pred (bb)) continue; for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) - did_something |= propagate_with_phi (bb, gsi.phi (), phivn, n); + did_something |= propagate_with_phi (bb, gsi.phi (), phivn, n, + &post_dominators_computed); } if (did_something) @@ -516,9 +524,10 @@ pass_phiprop::execute (function *fun) free (phivn); - free_dominance_info (CDI_POST_DOMINATORS); + if (post_dominators_computed) + free_dominance_info (CDI_POST_DOMINATORS); - return 0; + return did_something ? TODO_update_ssa : 0; } } // anon namespace