From patchwork Fri Jan 12 14:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 84000 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 4DACC3858292 for ; Fri, 12 Jan 2024 14:16:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 72C323858D20 for ; Fri, 12 Jan 2024 14:16:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72C323858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 72C323858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705068980; cv=none; b=a/77d/TuRGXaqqnxnsnsq7mUZ1KBPofth80rNciwsucUWCN7g5FwWR/ckaPT8H4V/7/PRp4dBK2VSEqULb6u9gyVIpfDSfOLavD5Vg2PbtCaIU0nDRVysx1Mr6/LEEoyQfLW6ZZMKsqHk6MmfkVcbqKBvtesqHrJ+q+RB/lb2OI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705068980; c=relaxed/simple; bh=zi3iVw1OGtGRPcaC9KAIMnPKOcsGcizOJs3znOD0sIc=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=DcR59z7LRGqleXL9+XHpPGsOFWzNTUBIpkFg3zfe22r4yuRlO9utMvdQZNP4j/OyM1nueWsUgCdvngFpJ3i7PwoJQbueJ23k3rqxjAWgFs7IZF1qtHLYNy2JELF5Rlj6A3TljY9OoTB5Inszh3JP1j92hcMO+WvXTqGlhLLBckU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.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 smtp-out2.suse.de (Postfix) with ESMTPS id 52E461FCD9 for ; Fri, 12 Jan 2024 14:16:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705068976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=VbFX7iG5wktY1tJjlyf/N51FQ9Yd6SvACjjime9+o6M=; b=TFgh8FZgFFXSKi5I8B56RFra2EA+oVdpIB1h4SEpJDLNCaGiAg3sLU1ceSVbMosvwdGSYn rxMYcr3LVMZ8r8fN28GouGao8077BeDOhuu8/5eI4Zm+kbOc7Gt/E3CoWNpKsR5V1iD+GW MSWn7PgKLUFDXUDKeTpmGNszyWM81Ns= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705068976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=VbFX7iG5wktY1tJjlyf/N51FQ9Yd6SvACjjime9+o6M=; b=iHgxcVgazAKCgsLDDAqdiyPAUrnNXqDuE0YfaLerd6z7UGa/vmE4qz6pbFm9F8p/JgD2gz DAAHbYcgGyZmgyDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705068976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=VbFX7iG5wktY1tJjlyf/N51FQ9Yd6SvACjjime9+o6M=; b=TFgh8FZgFFXSKi5I8B56RFra2EA+oVdpIB1h4SEpJDLNCaGiAg3sLU1ceSVbMosvwdGSYn rxMYcr3LVMZ8r8fN28GouGao8077BeDOhuu8/5eI4Zm+kbOc7Gt/E3CoWNpKsR5V1iD+GW MSWn7PgKLUFDXUDKeTpmGNszyWM81Ns= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705068976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=VbFX7iG5wktY1tJjlyf/N51FQ9Yd6SvACjjime9+o6M=; b=iHgxcVgazAKCgsLDDAqdiyPAUrnNXqDuE0YfaLerd6z7UGa/vmE4qz6pbFm9F8p/JgD2gz DAAHbYcgGyZmgyDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 353D913782 for ; Fri, 12 Jan 2024 14:16:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ZXUUC7BJoWU+BAAAD6G6ig (envelope-from ) for ; Fri, 12 Jan 2024 14:16:16 +0000 Date: Fri, 12 Jan 2024 15:16:11 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109893 - allow more backwards jump threading MIME-Version: 1.0 Message-Id: <20240112141616.353D913782@imap1.dmz-prg2.suse.org> Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.997]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Currently we scale the number of stmts allowed for forward jump threading to limit those for backwards jump threading by applying a factor of two to the counted stmts. That doesn't allow fine-grained adjustments, like by a single stmt as needed for PR109893. The following changes the factor to be a percentage of the forward threading number and adjusts that percentage from 50 to 54, fixing the regression. Bootstrapped and tested on x86_64-unknown-linux-gnu, I'm cross-checking some FAILs I see. PR tree-optimization/109893 * params.opt (fsm-scale-path-stmts): Change to percentage and default to 54 from 50. * doc/invoke.texi (--param fsm-scale-path-stmts): Adjust. * tree-ssa-threadbackward.cc (back_threader_profitability::possibly_profitable_path_p): Adjust param_fsm_scale_path_stmts uses. (back_threader_profitability::profitable_path_p): Likewise. * gcc.dg/tree-ssa/pr109893.c: New testcase. --- gcc/doc/invoke.texi | 4 +-- gcc/params.opt | 4 +-- gcc/testsuite/gcc.dg/tree-ssa/pr109893.c | 33 ++++++++++++++++++++++++ gcc/tree-ssa-threadbackward.cc | 17 ++++++------ 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr109893.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b7a201317ce..7e19f0245de 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -16647,8 +16647,8 @@ Maximum number of arrays per scop. Max. size of loc list for which reverse ops should be added. @item fsm-scale-path-stmts -Scale factor to apply to the number of statements in a threading path -crossing a loop backedge when comparing to +Percentage of max-jump-thread-duplication-stmts to allow for the number of +statements in a threading path crossing a loop backedge. @option{--param=max-jump-thread-duplication-stmts}. @item uninit-control-dep-attempts diff --git a/gcc/params.opt b/gcc/params.opt index 5eb045b2e6c..dbfa8ece8e0 100644 --- a/gcc/params.opt +++ b/gcc/params.opt @@ -131,8 +131,8 @@ Common Joined UInteger Var(param_early_inlining_insns) Init(6) Optimization Para Maximal estimated growth of function body caused by early inlining of single call. -param=fsm-scale-path-stmts= -Common Joined UInteger Var(param_fsm_scale_path_stmts) Init(2) IntegerRange(1, 10) Param Optimization -Scale factor to apply to the number of statements in a threading path crossing a loop backedge when comparing to max-jump-thread-duplication-stmts. +Common Joined UInteger Var(param_fsm_scale_path_stmts) Init(54) IntegerRange(1, 100) Param Optimization +Percentage of max-jump-thread-duplication-stmts to allow for the number of statements in a threading path crossing a loop backedge. -param=fully-pipelined-fma= Common Joined UInteger Var(param_fully_pipelined_fma) Init(0) IntegerRange(0, 1) Param Optimization diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr109893.c b/gcc/testsuite/gcc.dg/tree-ssa/pr109893.c new file mode 100644 index 00000000000..5c98664df72 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr109893.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dom2" } */ + +void foo(void); +void bar(void); +static char a; +static int b, e, f; +static int *c = &b, *g; +int main() { + int *j = 0; + if (a) { + g = 0; + if (c) + bar(); + } else { + j = &e; + c = 0; + } + if (c == &f == b || c == &e) + ; + else + __builtin_unreachable(); + if (g || e) { + if (j == &e || j == 0) + ; + else + foo(); + } + a = 4; +} + +/* Jump threading in thread1 should enable to elide the call to foo. */ +/* { dg-final { scan-tree-dump-not "foo" "dom2" } } */ diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc index fcebcdb5eaa..3091ddf4af1 100644 --- a/gcc/tree-ssa-threadbackward.cc +++ b/gcc/tree-ssa-threadbackward.cc @@ -741,8 +741,8 @@ back_threader_profitability::possibly_profitable_path_p if ((!m_threaded_multiway_branch || !loop->latch || loop->latch->index == EXIT_BLOCK) - && (m_n_insns * param_fsm_scale_path_stmts - >= param_max_jump_thread_duplication_stmts)) + && (m_n_insns * 100 >= (param_max_jump_thread_duplication_stmts + * param_fsm_scale_path_stmts))) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, @@ -751,8 +751,9 @@ back_threader_profitability::possibly_profitable_path_p return false; } *large_non_fsm = (!(m_threaded_through_latch && m_threaded_multiway_branch) - && (m_n_insns * param_fsm_scale_path_stmts - >= param_max_jump_thread_duplication_stmts)); + && (m_n_insns * 100 + >= (param_max_jump_thread_duplication_stmts + * param_fsm_scale_path_stmts))); if (dump_file && (dump_flags & TDF_DETAILS)) fputc ('\n', dump_file); @@ -825,8 +826,8 @@ back_threader_profitability::profitable_path_p (const vec &m_path, if (!m_threaded_multiway_branch && *creates_irreducible_loop && (!(cfun->curr_properties & PROP_loop_opts_done) - || (m_n_insns * param_fsm_scale_path_stmts - >= param_max_jump_thread_duplication_stmts))) + || (m_n_insns * 100 >= (param_max_jump_thread_duplication_stmts + * param_fsm_scale_path_stmts)))) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, @@ -841,8 +842,8 @@ back_threader_profitability::profitable_path_p (const vec &m_path, case, drastically reduce the number of statements we are allowed to copy. */ if (!(m_threaded_through_latch && m_threaded_multiway_branch) - && (m_n_insns * param_fsm_scale_path_stmts - >= param_max_jump_thread_duplication_stmts)) + && (m_n_insns * 100 >= (param_max_jump_thread_duplication_stmts + * param_fsm_scale_path_stmts))) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file,