From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id CE8EE3858424; Fri, 29 Jul 2022 10:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE8EE3858424 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1891] tree-optimization/105679 - disable backward threading of unlikely entry X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: b5f5d1b36edbcd7d923f2e2653e54e52637c715b X-Git-Newrev: 49ba4fdeb648c149fa7d964ba812084262c3d06f Message-Id: <20220729100558.CE8EE3858424@sourceware.org> Date: Fri, 29 Jul 2022 10:05:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2022 10:05:58 -0000 https://gcc.gnu.org/g:49ba4fdeb648c149fa7d964ba812084262c3d06f commit r13-1891-g49ba4fdeb648c149fa7d964ba812084262c3d06f Author: Richard Biener Date: Fri Jul 29 10:40:34 2022 +0200 tree-optimization/105679 - disable backward threading of unlikely entry 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%] PR tree-optimization/105679 * tree-ssa-threadbackward.cc (back_threader_profitability::profitable_path_p): Avoid threading when the entry edge is probably never executed. Diff: --- 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) {