The following adjusts move_early_exit_stmts to track the last seen VUSE instead of getting it from the last store which could be a PHI where gimple_vuse doesn't work.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/113902 * tree-vect-loop.cc (move_early_exit_stmts): Track last_seen_vuse for VUSE updating. * gcc.dg/vect/pr113902.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr113902.c | 15 +++++++++++++++ gcc/tree-vect-loop.cc | 12 +++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr113902.c diff --git a/gcc/testsuite/gcc.dg/vect/pr113902.c b/gcc/testsuite/gcc.dg/vect/pr113902.c new file mode 100644 index 00000000000..a2fe3df26e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr113902.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ + +int g_66, g_80_2; +void func_1func_41(int p_43) +{ +lbl_1434: + g_80_2 = 0; + for (; g_80_2 <= 7; g_80_2 += 1) { + g_66 = 0; + for (; g_66 <= 7; g_66 += 1) + if (p_43) + goto lbl_1434; + } +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 04f4b5b6b2f..4e498bb45ad 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -11787,6 +11787,7 @@ move_early_exit_stmts (loop_vec_info loop_vinfo) basic_block dest_bb = LOOP_VINFO_EARLY_BRK_DEST_BB (loop_vinfo); gimple_stmt_iterator dest_gsi = gsi_after_labels (dest_bb); + tree last_seen_vuse = NULL_TREE; for (gimple *stmt : LOOP_VINFO_EARLY_BRK_STORES (loop_vinfo)) { /* We have to update crossed degenerate virtual PHIs. Simply @@ -11805,6 +11806,7 @@ move_early_exit_stmts (loop_vec_info loop_vinfo) } auto gsi = gsi_for_stmt (stmt); remove_phi_node (&gsi, true); + last_seen_vuse = vuse; continue; } @@ -11819,17 +11821,17 @@ move_early_exit_stmts (loop_vec_info loop_vinfo) gimple_stmt_iterator stmt_gsi = gsi_for_stmt (stmt); gsi_move_before (&stmt_gsi, &dest_gsi, GSI_NEW_STMT); + last_seen_vuse = gimple_vuse (stmt); } /* Update all the stmts with their new reaching VUSES. */ - tree vuse - = gimple_vuse (LOOP_VINFO_EARLY_BRK_STORES (loop_vinfo).last ()); for (auto p : LOOP_VINFO_EARLY_BRK_VUSES (loop_vinfo)) { if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, - "updating vuse to %T for load %G", vuse, p); - gimple_set_vuse (p, vuse); + "updating vuse to %T for load %G", + last_seen_vuse, p); + gimple_set_vuse (p, last_seen_vuse); update_stmt (p); } @@ -11837,7 +11839,7 @@ move_early_exit_stmts (loop_vec_info loop_vinfo) for (edge e : get_loop_exit_edges (LOOP_VINFO_LOOP (loop_vinfo))) if (!dominated_by_p (CDI_DOMINATORS, e->src, dest_bb)) if (gphi *phi = get_virtual_phi (e->dest)) - SET_PHI_ARG_DEF_ON_EDGE (phi, e, vuse); + SET_PHI_ARG_DEF_ON_EDGE (phi, e, last_seen_vuse); } /* Function vect_transform_loop. -- 2.35.3