From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 872A73858C2D; Fri, 13 May 2022 06:01:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 872A73858C2D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-380] [PR105455] Set edge probabilities when hardening conditionals X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/heads/master X-Git-Oldrev: 8ab4b484153031c407b7d8c760b6a2605da1199a X-Git-Newrev: 90a8eab4a1292430467f68b65e5127f7760acc94 Message-Id: <20220513060140.872A73858C2D@sourceware.org> Date: Fri, 13 May 2022 06:01:40 +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, 13 May 2022 06:01:40 -0000 https://gcc.gnu.org/g:90a8eab4a1292430467f68b65e5127f7760acc94 commit r13-380-g90a8eab4a1292430467f68b65e5127f7760acc94 Author: Alexandre Oliva Date: Wed May 11 04:27:42 2022 -0300 [PR105455] Set edge probabilities when hardening conditionals When turning unconditional edges into conditional, as in gimple-harden-conditionals.cc:insert_check_and_trap, the newly-created edge's probability comes out uninitialized, while the previously unconditional edge's probability is presumably profile_probability::always. Mixing initialized and uninitialized probabilities before expand breaks predict.cc:force_edge_cold: the initialized probability may end up copied to a REG_BR_PROB note in a conditional branch insn, but if force_edge_cold is called on that edge, it will find another edge with uninitialized probability and assume the note is absent. Later on, rtl_verify_edges complains that the note does not match the probability modified by force_edge_cold in the edge. This patch sets probabilities for edges affected by hardening of conditionals, both the newly-created edges to trap blocks and the previously-unconditional edges, so that the former are considered never taken, while the latter are confirmed as always taken. for gcc/ChangeLog PR rtl-optimization/105455 * gimple-harden-conditionals.cc (insert_check_and_trap): Set probabilities for newly-conditional edges. for gcc/testsuite/ChangeLog PR rtl-optimization/105455 * gcc.dg/pr105455.c: New. Diff: --- gcc/gimple-harden-conditionals.cc | 2 ++ gcc/testsuite/gcc.dg/pr105455.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc index c7e5e077a74..19ceb8a4bd6 100644 --- a/gcc/gimple-harden-conditionals.cc +++ b/gcc/gimple-harden-conditionals.cc @@ -254,8 +254,10 @@ insert_check_and_trap (location_t loc, gimple_stmt_iterator *gsip, equality. */ single_succ_edge (chk)->flags &= ~EDGE_FALLTHRU; single_succ_edge (chk)->flags |= neg_true_false_flag; + single_succ_edge (chk)->probability = profile_probability::always (); edge e = make_edge (chk, trp, true_false_flag); e->goto_locus = loc; + e->probability = profile_probability::never (); if (dom_info_available_p (CDI_DOMINATORS)) set_immediate_dominator (CDI_DOMINATORS, trp, chk); diff --git a/gcc/testsuite/gcc.dg/pr105455.c b/gcc/testsuite/gcc.dg/pr105455.c new file mode 100644 index 00000000000..81e9154baa1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105455.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fharden-conditional-branches -funroll-loops --param max-loop-header-insns=1" } */ + +__attribute__ ((cold)) void +bar (void); + +void +foo (int x) +{ + if (x) + { + int i; + + for (i = 0; i < 101; ++i) + bar (); + } +}