From: Tamar Christina Date: Mon, 8 Dec 2025 09:10:58 +0000 (+0000) Subject: vect: move the condition down into the loop checking every scalar load [PR122868] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1db03274f1371e0bce5b39f86eda1437502ac28e;p=thirdparty%2Fgcc.git vect: move the condition down into the loop checking every scalar load [PR122868] As Richi suggested this moves the check into the loop so we check every load. I had initially not done this because I figured the loads would be treated as a group anyway and the group would be valid or not as a whole. But for invariants they could be a group, but not all the loads within range of a known bounds. gcc/ChangeLog: PR tree-optimization/122868 * tree-vect-stmts.cc (vectorizable_load): Move check for invariant loads down into the loop. --- diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index dc155dcc7fe..95f015f9298 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -9920,36 +9920,35 @@ vectorizable_load (vec_info *vinfo, bool hoist_p = (LOOP_VINFO_NO_DATA_DEPENDENCIES (loop_vinfo) && !nested_in_vect_loop); - /* It is unsafe to hoist a conditional load over the conditions that make - it valid. When early break this means that any invariant load can't be - hoisted unless it's in the loop header or if we know something else has - verified the load is valid to do. Alignment peeling would do this - since getting through the prologue means the load was done at least - once and so the vector main body is free to hoist it. However today - GCC will hoist the load above the PFA loop. As such that makes it - still invalid and so we can't allow it today. */ - auto stmt_bb - = gimple_bb (STMT_VINFO_STMT ( - vect_orig_stmt (SLP_TREE_SCALAR_STMTS (slp_node)[0]))); - if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo) - && !DR_SCALAR_KNOWN_BOUNDS (dr_info) - && stmt_bb != loop->header) - { - if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) - && dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + bool uniform_p = true; + for (stmt_vec_info sinfo : SLP_TREE_SCALAR_STMTS (slp_node)) + { + /* It is unsafe to hoist a conditional load over the conditions that + make it valid. When early break this means that any invariant load + can't be hoisted unless it's in the loop header or if we know + something else has verified the load is valid to do. Alignment + peeling would do this since getting through the prologue means the + load was done at least once and so the vector main body is free to + hoist it. However today GCC will hoist the load above the PFA + loop. As such that makes it still invalid and so we can't allow it + today. */ + if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo) + && !DR_SCALAR_KNOWN_BOUNDS (STMT_VINFO_DR_INFO (sinfo)) + && gimple_bb (STMT_VINFO_STMT (vect_orig_stmt (sinfo))) + != loop->header) + { + if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) + && dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not hoisting invariant load due to early break" "constraints\n"); - else if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, + else if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, "not hoisting invariant load due to early break" "constraints\n"); - hoist_p = false; - } + hoist_p = false; + } - bool uniform_p = true; - for (stmt_vec_info sinfo : SLP_TREE_SCALAR_STMTS (slp_node)) - { hoist_p = hoist_p && hoist_defs_of_uses (sinfo->stmt, loop, false); if (sinfo != SLP_TREE_SCALAR_STMTS (slp_node)[0]) uniform_p = false;