https://gcc.gnu.org/g:2d4b7b983c7232325a9a7659e37143bdd5112dcc
commit r16-3367-g2d4b7b983c7232325a9a7659e37143bdd5112dcc Author: Richard Biener <[email protected]> Date: Mon Aug 25 11:02:52 2025 +0200 tree-optimization/121638 - missed SLP discovery of live induction The following fixes a missed SLP discovery of a live induction. Our pattern matching of those fails because of the PR81529 fix which I think was misguided and should now no longer be relevant. So this essentially reverts that fix. I have added a GIMPLE testcase to increase the chance the particular IL is preserved through the future. This shows that how we make some IVs live because of early-break isn't quite correct, so I had to preserve a hack here. Hopefully to be investigated at some point. PR tree-optimization/121638 * tree-vect-stmts.cc (process_use): Do not make induction PHI backedge values relevant. * gcc.dg/vect/pr121638.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/pr121638.c | 74 ++++++++++++++++++++++++++++++++++++ gcc/tree-vect-stmts.cc | 14 ++++--- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr121638.c b/gcc/testsuite/gcc.dg/vect/pr121638.c new file mode 100644 index 000000000000..52d5d6d3bd79 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121638.c @@ -0,0 +1,74 @@ +/* { dg-additional-options "-fgimple -fno-tree-scev-cprop" } */ + +#include "tree-vect.h" + +int a, b, f, j, i, *m, n, o, p = 1, q; + +int __GIMPLE (ssa,guessed_local(1073741824),startwith("loop")) +main () +{ + int D_3005; + int D_3003; + int d; + int * e; + long unsigned int _9; + long unsigned int _10; + int * _11; + int _15; + int _32; + + __BB(2,guessed_local(1073741824)): + check_vect (); + e_6 = __builtin_malloc (64ul); + goto __BB3(precise(134217728)); + + __BB(3,loop_header(2),guessed_local(8687547538)): + d_29 = __PHI (__BB3: d_8, __BB2: 0); + d_8 = d_29 + 1; + _9 = (long unsigned int) d_29; + _10 = _9 * 4ul; + _11 = e_6 + _10; + __MEM <int> (_11) = d_29; + if (d_8 <= 15) + goto __BB3(guessed(119453778)); + else + goto __BB4(guessed(14763950)); + + __BB(4,guessed_local(955630224)): + if (d_8 != 16) + goto __BB9(guessed(58814510)); + else + goto __BB5(guessed(75403218)); + + __BB(5,guessed_local(536870912)): + a = 0; + if (d_8 > 0) + goto __BB6(guessed(119453778)); + else + goto __BB8(guessed(14763950)); + + __BB(6,loop_header(1),guessed_local(4343773769)): + _32 = __PHI (__BB6: _15, __BB5: 0); + _15 = _32 + 1; + if (d_29 > _32) + goto __BB6(guessed(119453778)); + else + goto __BB7(guessed(14763950)); + + __BB(7,guessed_local(477815112)): + a = _15; + goto __BB8(precise(134217728)); + + __BB(8,guessed_local(1073741824)): + __builtin_free (e_6); + f = 0; + return 0; + + __BB(9,precise(0)): + a = d_8; + f = 1; + __builtin_abort (); + +} + + diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 47cd29fb1b89..653c5e38e274 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -417,7 +417,9 @@ vect_stmt_relevant_p (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, /* Check if it's a not live PHI and multiple exits. In this case there will be a usage later on after peeling which is needed for the - alternate exit. */ + alternate exit. + ??? Unless the PHI was marked live because of early + break, which also needs the latch def live and vectorized. */ if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo) && is_a <gphi *> (stmt) && gimple_bb (stmt) == LOOP_VINFO_LOOP (loop_vinfo)->header @@ -655,14 +657,15 @@ process_use (stmt_vec_info stmt_vinfo, tree use, loop_vec_info loop_vinfo, } /* We are also not interested in uses on loop PHI backedges that are inductions. Otherwise we'll needlessly vectorize the IV increment - and cause hybrid SLP for SLP inductions. Unless the PHI is live - of course. */ + and cause hybrid SLP for SLP inductions. */ else if (gimple_code (stmt_vinfo->stmt) == GIMPLE_PHI && STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_induction_def - && ! STMT_VINFO_LIVE_P (stmt_vinfo) && (PHI_ARG_DEF_FROM_EDGE (stmt_vinfo->stmt, loop_latch_edge (bb->loop_father)) - == use)) + == use) + && (!LOOP_VINFO_EARLY_BREAKS (loop_vinfo) + || (gimple_bb (stmt_vinfo->stmt) + != LOOP_VINFO_LOOP (loop_vinfo)->header))) { if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, @@ -670,7 +673,6 @@ process_use (stmt_vec_info stmt_vinfo, tree use, loop_vec_info loop_vinfo, return opt_result::success (); } - vect_mark_relevant (worklist, dstmt_vinfo, relevant, false); return opt_result::success (); }
