Message ID | 20220729085417.4B50F13A1B@imap2.suse-dmz.suse.de |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp694376pxt; Fri, 29 Jul 2022 01:55:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sPwl7O+QQwB6Htx2uQgPPiUH301eD7K4M0eYB4TRhte2v084JI7FbkOCquPqc4UVJwEjGN X-Received: by 2002:a17:906:58d6:b0:72f:25c0:af2b with SMTP id e22-20020a17090658d600b0072f25c0af2bmr2207494ejs.326.1659084932541; Fri, 29 Jul 2022 01:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659084932; cv=none; d=google.com; s=arc-20160816; b=JbB2X6FUGJk7QCiYg9N+cOEZrrBl5AJMi8A2bruirFBje/LmnUiNvMTni2E0AQUjFz YR9zpz62NgNRUOqBhVrb6ru6hWzLA0kKE9GmGeUmOrWitfCMkP13Mzecb6e/xLeS0Aav XGEo/EJNC2NorvYzFk/8ylCrwAurgrJdRm09JeqxwpiwxGQ2OMVvNeG8bV6qKlOwsxu7 NqBn5lt5I3DeefOymKqTuH01/XqWKMC9ATizioSJUu3QbrjqBA+a1Dv0ytbdrXQ4fTLr BQHOn1jAK1QXswz54YQwruvGyA2qbnxPtu4/7CpRwB72SWxongElRFQwUEM8+V4SGfnd DfqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=BfNbILRK3JmyWbku0uawlZ/xKTAa0a9RYMCwI3MuJA0=; b=kuC2VLRMJISLero/wrY0IA9P/0/ST0hH6xzWP/UtX9lFcY5ZpzKFjVq4o5oeK6N39i yENGjGBwjXEM7+d0DrXNEDBNAJ5jkEu46N42wndM9oXQu2EEMWoTUCj+Xx/PGQNfj9rj 7bx/uml1LtZSISeBx+61+eYZckPf1QVVWO9wQcfaeAczYpTISc0t4L9NiShzPSbK+R1f 3wyaGrs2LuNHRPpC8xDwluADzaB/H//kJ1nUEJLbAPO/3KIhoZY5alqCoOXSe7LkSDmL jh5G/B0dVONkojyHTBB/Ykc/oZpEb/d9URhbSf1RWf8BG7U2F/6Tg5frVXRY/vmVdfgS xHAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FPdkuMMq; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o9-20020a056402438900b0043cea4805e3si3347024edc.304.2022.07.29.01.55.32 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 01:55:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FPdkuMMq; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 28AEE3857B95 for <ouuuleilei@gmail.com>; Fri, 29 Jul 2022 08:55:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28AEE3857B95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659084931; bh=BfNbILRK3JmyWbku0uawlZ/xKTAa0a9RYMCwI3MuJA0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FPdkuMMqN4qJNpIpwTvJ2OLctQ/RGqb+nz5h+/h2JUPPVBqgLHdh2JOTeDjfDoF6k K+7mGq/QDKt3K4hloY2iXG9RHaplEeVKZilv2/Ie0qKiEOrQ9Avfk6rQu59y4wzKox zfi/GnlL0J4UiOB7LPylXExTt/HsaaSwPQ/uTFbw= 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 <gcc-patches@gcc.gnu.org>; 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 <rguenther@suse.de>); 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 Content-Type: text/plain; charset=US-ASCII 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Richard Biener <rguenther@suse.de> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1739676642176491604?= X-GMAIL-MSGID: =?utf-8?q?1739676642176491604?= |
Series |
tree-optimization/105679 - disable backward threading of unlikely entry
|
|
Commit Message
Richard Biener
July 29, 2022, 8:54 a.m. UTC
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 <bb 3>; [0.00%] else goto <bb 4>; [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 <bb 7>; [34.00%] else goto <bb 5>; [66.00%] ;; basic block 5, loop depth 0, count 708669600 (estimated locally), maybe hot if (irq_1(D) == 1) goto <bb 7>; [20.97%] else goto <bb 6>; [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(+)
Comments
On Fri, Jul 29, 2022 at 11:02 AM Richard Biener <rguenther@suse.de> wrote: > > 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 <bb 3>; [0.00%] > else > goto <bb 4>; [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 <bb 7>; [34.00%] > else > goto <bb 5>; [66.00%] > > ;; basic block 5, loop depth 0, count 708669600 (estimated locally), maybe hot if (irq_1(D) == 1) > goto <bb 7>; [20.97%] > else > goto <bb 6>; [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). Sounds reasonable, if for no other reason than to quiet down the annoyingly large amount of false positives we have because of aggressive threading, or better ranges as a whole. How does this fit in with Jeff's original idea of isolating known problematic paths (null dereferences?), which in theory are also unlikely? Thanks for doing this. Aldy > > 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<basic_block> &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) > { > -- > 2.35.3 >
On Fri, 29 Jul 2022, Aldy Hernandez wrote: > On Fri, Jul 29, 2022 at 11:02 AM Richard Biener <rguenther@suse.de> wrote: > > > > 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 <bb 3>; [0.00%] > > else > > goto <bb 4>; [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 <bb 7>; [34.00%] > > else > > goto <bb 5>; [66.00%] > > > > ;; basic block 5, loop depth 0, count 708669600 (estimated locally), maybe hot if (irq_1(D) == 1) > > goto <bb 7>; [20.97%] > > else > > goto <bb 6>; [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). > > Sounds reasonable, if for no other reason than to quiet down the > annoyingly large amount of false positives we have because of > aggressive threading, or better ranges as a whole. > > How does this fit in with Jeff's original idea of isolating known > problematic paths (null dereferences?), which in theory are also > unlikely? If profile estimation gets to see those the paths should turn unlikely. Path isolation should also make sure to adjust the profile accordingly, though local profile adjustments are somewhat difficult. Richard. > Thanks for doing this. > Aldy > > > > > 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<basic_block> &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) > > { > > -- > > 2.35.3 > > > >
On 7/29/2022 2:54 AM, Richard Biener via Gcc-patches wrote: > 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 <bb 3>; [0.00%] > else > goto <bb 4>; [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 <bb 7>; [34.00%] > else > goto <bb 5>; [66.00%] > > ;; basic block 5, loop depth 0, count 708669600 (estimated locally), maybe hot if (irq_1(D) == 1) > goto <bb 7>; [20.97%] > else > goto <bb 6>; [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. OK. And more generally I'm absolutely OK with improving the costing heuristics. The one thing we need to keep in mind when adding this kind of check is that we may start seeing new diagnostics from the middle end -- while the path may not be profitable to thread from a performance standpoint, it may be useful to thread from a diagnostic standpoint. But I'd argue that for such cases we really want to move to a model where the predicate analysis bits are used consistently to prune away "can't happen" cases for middle end diagnostics rather than relying on threading to optimize away can't happen cold paths. Jeff
Hi Richi, > On 29 Jul 2022, at 09:54, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > 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 This breaks bootstrap on i686-darwin{9,17} with what looks like a valid warning (werrors on stage2) cc1plus … -O2 -Wall … is enough to. I can repeat it on a cross from x86_64-darwin19, so I can probably reduce the .ii (it’s like 2M5 raw) and file a PR if you like - depends if the solution might be obvious to you … thanks Iain -------- In file included from /src-local/gcc-master/gcc/hash-table.h:248, from /src-local/gcc-master/gcc/coretypes.h:486, from /src-local/gcc-master/gcc/tree-ssa-threadbackward.cc:22: In member function ‘T& vec<T, A, vl_embed>::operator[](unsigned int) [with T = basic_block_def*; A = va_heap]’, inlined from ‘const T& vec<T>::operator[](unsigned int) const [with T = basic_block_def*]’ at /src-local/gcc-master/gcc/vec.h:1486:20, inlined from ‘bool back_threader_profitability::profitable_path_p(const vec<basic_block_def*>&, tree, edge, bool*)’ at /src-local/gcc-master/gcc/tree-ssa-threadbackward.cc:781:37: /src-local/gcc-master/gcc/vec.h:890:19: warning: array subscript 4294967294 is above array bounds of ‘basic_block_def* [1]’ [-Warray-bounds] 890 | return m_vecdata[ix]; | ~~~~~~~~~^ /src-local/gcc-master/gcc/vec.h: In member function ‘bool back_threader_profitability::profitable_path_p(const vec<basic_block_def*>&, tree, edge, bool*)’: /src-local/gcc-master/gcc/vec.h:635:5: note: while referencing ‘vec<basic_block_def*, va_heap, vl_embed>::m_vecdata’ 635 | T m_vecdata[1]; | ^~~~~~~~~ =====
On 7/31/2022 1:17 PM, Iain Sandoe via Gcc-patches wrote: > Hi Richi, > >> On 29 Jul 2022, at 09:54, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: >> >> 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 > This breaks bootstrap on i686-darwin{9,17} with what looks like a valid warning (werrors on stage2) > > cc1plus … -O2 -Wall … is enough to. > > I can repeat it on a cross from x86_64-darwin19, so I can probably reduce the .ii (it’s like 2M5 raw) and file a PR if you like - depends if the solution might be obvious to you … I suspect what's happening here is by suppressing the jump thread we're leaving an unexecutable path through the CFG in the IL. The warning is likely on that unexecutable path or at a join point where the unexecutable path re-joins the main path through the CFG. Jeff
On Sun, 31 Jul 2022, Iain Sandoe wrote: > Hi Richi, > > > On 29 Jul 2022, at 09:54, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > 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 > > This breaks bootstrap on i686-darwin{9,17} with what looks like a valid warning (werrors on stage2) > > cc1plus … -O2 -Wall … is enough to. > > I can repeat it on a cross from x86_64-darwin19, so I can probably reduce the .ii (it’s like 2M5 raw) and file a PR if you like - depends if the solution might be obvious to you … Can you open a bugreport and attach full preprocessed source at start? Note at the start of the function we have if (m_path.length () <= 1) return false; so edge entry = find_edge (m_path[m_path.length () - 1], m_path[m_path.length () - 2]); is known to not access m_path out-of-bounds ... Thanks, Richard. > > thanks > Iain > > -------- > > In file included from /src-local/gcc-master/gcc/hash-table.h:248, > from /src-local/gcc-master/gcc/coretypes.h:486, > from /src-local/gcc-master/gcc/tree-ssa-threadbackward.cc:22: > In member function ‘T& vec<T, A, vl_embed>::operator[](unsigned int) [with T = basic_block_def*; A = va_heap]’, > inlined from ‘const T& vec<T>::operator[](unsigned int) const [with T = basic_block_def*]’ at /src-local/gcc-master/gcc/vec.h:1486:20, > inlined from ‘bool back_threader_profitability::profitable_path_p(const vec<basic_block_def*>&, tree, edge, bool*)’ at /src-local/gcc-master/gcc/tree-ssa-threadbackward.cc:781:37: > /src-local/gcc-master/gcc/vec.h:890:19: warning: array subscript 4294967294 is above array bounds of ‘basic_block_def* [1]’ [-Warray-bounds] > 890 | return m_vecdata[ix]; > | ~~~~~~~~~^ > /src-local/gcc-master/gcc/vec.h: In member function ‘bool back_threader_profitability::profitable_path_p(const vec<basic_block_def*>&, tree, edge, bool*)’: > /src-local/gcc-master/gcc/vec.h:635:5: note: while referencing ‘vec<basic_block_def*, va_heap, vl_embed>::m_vecdata’ > 635 | T m_vecdata[1]; > | ^~~~~~~~~ > > =====
> On 1 Aug 2022, at 09:21, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > On Sun, 31 Jul 2022, Iain Sandoe wrote: > >> Hi Richi, >> >>> On 29 Jul 2022, at 09:54, Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: >>> >>> 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 >> >> This breaks bootstrap on i686-darwin{9,17} with what looks like a valid warning (werrors on stage2) >> >> cc1plus … -O2 -Wall … is enough to. >> >> I can repeat it on a cross from x86_64-darwin19, so I can probably reduce the .ii (it’s like 2M5 raw) and file a PR if you like - depends if the solution might be obvious to you … > > Can you open a bugreport and attach full preprocessed source at start? https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106496 > Note at the start of the function we have > > if (m_path.length () <= 1) > return false; > > so > > edge entry = find_edge (m_path[m_path.length () - 1], > m_path[m_path.length () - 2]); > > is known to not access m_path out-of-bounds ... yes, I saw that .. so I guess somehow that information is getting dropped. thanks Iain > > Thanks, > Richard. > >> >> thanks >> Iain >> >> -------- >> >> In file included from /src-local/gcc-master/gcc/hash-table.h:248, >> from /src-local/gcc-master/gcc/coretypes.h:486, >> from /src-local/gcc-master/gcc/tree-ssa-threadbackward.cc:22: >> In member function ‘T& vec<T, A, vl_embed>::operator[](unsigned int) [with T = basic_block_def*; A = va_heap]’, >> inlined from ‘const T& vec<T>::operator[](unsigned int) const [with T = basic_block_def*]’ at /src-local/gcc-master/gcc/vec.h:1486:20, >> inlined from ‘bool back_threader_profitability::profitable_path_p(const vec<basic_block_def*>&, tree, edge, bool*)’ at /src-local/gcc-master/gcc/tree-ssa-threadbackward.cc:781:37: >> /src-local/gcc-master/gcc/vec.h:890:19: warning: array subscript 4294967294 is above array bounds of ‘basic_block_def* [1]’ [-Warray-bounds] >> 890 | return m_vecdata[ix]; >> | ~~~~~~~~~^ >> /src-local/gcc-master/gcc/vec.h: In member function ‘bool back_threader_profitability::profitable_path_p(const vec<basic_block_def*>&, tree, edge, bool*)’: >> /src-local/gcc-master/gcc/vec.h:635:5: note: while referencing ‘vec<basic_block_def*, va_heap, vl_embed>::m_vecdata’ >> 635 | T m_vecdata[1]; >> | ^~~~~~~~~ >> >> ===== > > -- > Richard Biener <rguenther@suse.de> > SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, > Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; > HRB 36809 (AG Nuernberg)
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<basic_block> &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) {