From patchwork Fri Jul 29 08:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 56427 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 4682F3857C7B for ; Fri, 29 Jul 2022 08:55:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4682F3857C7B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659084917; bh=BfNbILRK3JmyWbku0uawlZ/xKTAa0a9RYMCwI3MuJA0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=O3CmSX3bqfAPPWsorbDVu2HF6ah6ASb+GB0IChu9HM2CUjQmoszmNJAGN62ukW2Za Skve8dkQqSXWdr0MWW8zpFntvxlwZZO/kg884S+barXDiax9EBzhfOlCHAC9oSXloH leACITHDqrnRQo+UYnkXE4nnztzdPwEGKGyoydD8= 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 [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id DC3EC3857C72 for ; Fri, 29 Jul 2022 08:54:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC3EC3857C72 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6B5BC33963; Fri, 29 Jul 2022 08:54:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4B50F13A1B; Fri, 29 Jul 2022 08:54:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QyJbETmg42LwUwAAMHmgww (envelope-from ); Fri, 29 Jul 2022 08:54:17 +0000 Date: Fri, 29 Jul 2022 10:54:16 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/105679 - disable backward threading of unlikely entry MIME-Version: 1.0 Message-Id: <20220729085417.4B50F13A1B@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-12.0 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 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" The following makes the backward threader reject threads whose entry edge is probably never executed according to the profile. That in particular, for the testcase, avoids threading the irq == 1 check on the path where irq > 31, thereby avoiding spurious -Warray-bounds diagnostics if (irq_1(D) > 31) goto ; [0.00%] else goto ; [100.00%] ;; basic block 3, loop depth 0, count 0 (precise), probably never executed _2 = (unsigned long) irq_1(D); __builtin___ubsan_handle_shift_out_of_bounds (&*.Lubsan_data0, 1, _2); _3 = 1 << irq_1(D); mask_4 = (u32) _3; entry = instance_5(D)->array[irq_1(D)]; capture (mask_4); if (level_6(D) != 0) goto ; [34.00%] else goto ; [66.00%] ;; basic block 5, loop depth 0, count 708669600 (estimated locally), maybe hot if (irq_1(D) == 1) goto ; [20.97%] else goto ; [79.03%] Bootstrap and regtest running on x86_64-unknown-linux-gnu. The testcase in the PR requries both ubsan and sancov so I'm not sure where to put it but IIRC there were quite some duplicate PRs wrt threading unlikely paths exposing diagnostics, eventually some testcase will come out of those (when we identify them). Note the patch is quite conservative in only disabling likely never executed paths rather than requiring maybe_hot_edge_p (OTOH those are somewhat similar in the end). I'm going to push it when testing finishes but maybe there are some testcases to adjust. PR tree-optimization/105679 * tree-ssa-threadbackwards.cc (back_threader_profitability::profitable_path_p): Avoid threading when the entry edge is probably never executed. --- gcc/tree-ssa-threadbackward.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc index 3519aca84cd..90f5331c265 100644 --- a/gcc/tree-ssa-threadbackward.cc +++ b/gcc/tree-ssa-threadbackward.cc @@ -777,6 +777,15 @@ back_threader_profitability::profitable_path_p (const vec &m_path, "exceeds PARAM_MAX_FSM_THREAD_PATH_INSNS.\n"); return false; } + edge entry = find_edge (m_path[m_path.length () - 1], + m_path[m_path.length () - 2]); + if (probably_never_executed_edge_p (cfun, entry)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, " FAIL: Jump-thread path not considered: " + "path entry is probably never executed.\n"); + return false; + } } else if (!m_speed_p && n_insns > 1) {