https://gcc.gnu.org/g:3be614e3476a4d57186aedf7335fd87f25b4db71
commit r17-5662-g3be614e3476a4d57186aedf7335fd87f25b4db71 Author: Jakub Jelinek <[email protected]> Date: Wed Oct 28 13:25:12 2026 +0100 cfgrtl: Small cleanup in force_nonfallthru_and_redirect As I wrote earlier, the function has many different rtx note; variables. This patch changes the code to use the C++ simple declarations as condition to limit their scope (with one rtx note; remaining at the outermost scope, but that one is sometimes used across these). Note, I'm not 100% sure about the last while, while the patch preserves the previous behavior, I'm not sure if there can be multiple REG_LABEL_OPERAND notes with the same operand on the same insn. If yes, perhaps instead of calling find_reg_note and starting from the beginning of list after each adjustment (so O(N^2) in number of such notes), if no, just if and not while could be used instead. 2026-10-28 Jakub Jelinek <[email protected]> * cfgrtl.cc (force_nonfallthru_and_redirect): Replace some note variables in the function with C++ simple declaration as condition. Reviewed-by: Richard Biener <[email protected]> Diff: --- gcc/cfgrtl.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc index c89f28a51c2a..b128f179b2b9 100644 --- a/gcc/cfgrtl.cc +++ b/gcc/cfgrtl.cc @@ -1533,7 +1533,6 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label) && any_condjump_p (BB_END (e->src)) && JUMP_LABEL (BB_END (e->src)) == BB_HEAD (e->dest)) { - rtx note; edge b = unchecked_make_edge (e->src, target, 0); bool redirected; @@ -1541,8 +1540,7 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label) block_label (target), 0); gcc_assert (redirected); - note = find_reg_note (BB_END (e->src), REG_BR_PROB, NULL_RTX); - if (note) + if (rtx note = find_reg_note (BB_END (e->src), REG_BR_PROB, NULL_RTX)) { int prob = XINT (note, 0); @@ -1675,28 +1673,24 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label) } rtx_insn *insn = BB_END (new_edge->src); - rtx note; rtx_insn *old_label = BB_HEAD (e->dest); rtx_insn *new_label = BB_HEAD (jump_block); if (JUMP_LABEL (insn) == old_label) { JUMP_LABEL (insn) = new_label; - note = find_reg_note (insn, REG_LABEL_TARGET, new_label); - if (note) + if (rtx note = find_reg_note (insn, REG_LABEL_TARGET, new_label)) remove_note (insn, note); } else { - note = find_reg_note (insn, REG_LABEL_TARGET, old_label); - if (note) + if (rtx note = find_reg_note (insn, REG_LABEL_TARGET, old_label)) remove_note (insn, note); if (JUMP_LABEL (insn) != new_label && !find_reg_note (insn, REG_LABEL_TARGET, new_label)) add_reg_note (insn, REG_LABEL_TARGET, new_label); } - while ((note = find_reg_note (insn, REG_LABEL_OPERAND, old_label)) - != NULL_RTX) + while (rtx note = find_reg_note (insn, REG_LABEL_OPERAND, old_label)) XEXP (note, 0) = new_label; }
