@@ -9788,36 +9788,22 @@ permute_vec_elements (vec_info *vinfo,
9788
9788
return data_ref;
9789
9789
}
9790
9790
9791
- /* Comparator for qsort, sorting after GIMPLE UID. */
9792
-
9793
- static int
9794
- sort_after_uid (const void *a_, const void *b_)
9795
- {
9796
- const gimple *a = *(const gimple * const *)a_;
9797
- const gimple *b = *(const gimple * const *)b_;
9798
- if (gimple_uid (a) < gimple_uid (b))
9799
- return -1 ;
9800
- else if (gimple_uid (a) > gimple_uid (b))
9801
- return 1 ;
9802
- return 0 ;
9803
- }
9804
-
9805
9791
/* Hoist the definitions of all SSA uses on STMT_INFO out of the loop LOOP,
9806
9792
inserting them on the loops preheader edge. Returns true if we
9807
9793
were successful in doing so (and thus STMT_INFO can be moved then),
9808
9794
otherwise returns false. HOIST_P indicates if we want to hoist the
9809
9795
definitions of all SSA uses, it would be false when we are costing. */
9810
9796
9811
9797
static bool
9812
- hoist_defs_of_uses (stmt_vec_info stmt_info , class loop *loop, bool hoist_p)
9798
+ hoist_defs_of_uses (gimple *stmt , class loop *loop, bool hoist_p)
9813
9799
{
9814
9800
ssa_op_iter i;
9815
- tree op ;
9816
- auto_vec<gimple * , 8 > to_hoist;
9801
+ use_operand_p use_p ;
9802
+ auto_vec<use_operand_p , 8> to_hoist;
9817
9803
9818
- FOR_EACH_SSA_TREE_OPERAND (op, stmt_info-> stmt , i, SSA_OP_USE)
9804
+ FOR_EACH_SSA_USE_OPERAND (use_p, stmt, i, SSA_OP_USE)
9819
9805
{
9820
- gimple *def_stmt = SSA_NAME_DEF_STMT (op );
9806
+ gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p) );
9821
9807
if (!gimple_nop_p (def_stmt)
9822
9808
&& flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)))
9823
9809
{
@@ -9827,7 +9813,9 @@ hoist_defs_of_uses (stmt_vec_info stmt_info, class loop *loop, bool hoist_p)
9827
9813
dependencies within them. */
9828
9814
tree op2;
9829
9815
ssa_op_iter i2;
9830
- if (gimple_code (def_stmt) == GIMPLE_PHI)
9816
+ if (gimple_code (def_stmt) == GIMPLE_PHI
9817
+ || (single_ssa_def_operand (def_stmt, SSA_OP_DEF)
9818
+ == NULL_DEF_OPERAND_P))
9831
9819
return false;
9832
9820
FOR_EACH_SSA_TREE_OPERAND (op2, def_stmt, i2, SSA_OP_USE)
9833
9821
{
@@ -9836,7 +9824,7 @@ hoist_defs_of_uses (stmt_vec_info stmt_info, class loop *loop, bool hoist_p)
9836
9824
&& flow_bb_inside_loop_p (loop, gimple_bb (def_stmt2)))
9837
9825
return false;
9838
9826
}
9839
- to_hoist.safe_push (def_stmt );
9827
+ to_hoist.safe_push (use_p );
9840
9828
}
9841
9829
}
9842
9830
@@ -9846,14 +9834,21 @@ hoist_defs_of_uses (stmt_vec_info stmt_info, class loop *loop, bool hoist_p)
9846
9834
if (!hoist_p)
9847
9835
return true;
9848
9836
9849
- /* Preserve UID order, otherwise we break dominance checks. */
9850
- to_hoist. qsort (sort_after_uid);
9851
-
9852
- for (gimple *def_stmt : to_hoist)
9837
+ /* Instead of moving defs we copy them so we can zero their UID to not
9838
+ confuse dominance queries in the preheader. */
9839
+ gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
9840
+ for (use_operand_p use_p : to_hoist)
9853
9841
{
9854
- gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt);
9855
- gsi_remove (&gsi, false );
9856
- gsi_insert_on_edge_immediate (loop_preheader_edge (loop), def_stmt);
9842
+ gimple *def_stmt = SSA_NAME_DEF_STMT (USE_FROM_PTR (use_p));
9843
+ gimple *copy = gimple_copy (def_stmt);
9844
+ gimple_set_uid (copy, 0);
9845
+ def_operand_p def_p = single_ssa_def_operand (def_stmt, SSA_OP_DEF);
9846
+ tree new_def = duplicate_ssa_name (DEF_FROM_PTR (def_p), copy);
9847
+ update_stmt (copy);
9848
+ def_p = single_ssa_def_operand (copy, SSA_OP_DEF);
9849
+ SET_DEF (def_p, new_def);
9850
+ SET_USE (use_p, new_def);
9851
+ gsi_insert_before (&gsi, copy, GSI_SAME_STMT);
9857
9852
}
9858
9853
9859
9854
return true;
@@ -10227,7 +10222,7 @@ vectorizable_load (vec_info *vinfo,
10227
10222
transform time. */
10228
10223
bool hoist_p = (LOOP_VINFO_NO_DATA_DEPENDENCIES (loop_vinfo)
10229
10224
&& !nested_in_vect_loop
10230
- && hoist_defs_of_uses (stmt_info, loop, !costing_p ));
10225
+ && hoist_defs_of_uses (stmt_info->stmt , loop, false ));
10231
10226
if (costing_p)
10232
10227
{
10233
10228
enum vect_cost_model_location cost_loc
@@ -10264,6 +10259,7 @@ vectorizable_load (vec_info *vinfo,
10264
10259
gimple *new_stmt = gimple_build_assign (scalar_dest, rhs);
10265
10260
gimple_set_vuse (new_stmt, vuse);
10266
10261
gsi_insert_on_edge_immediate (pe, new_stmt);
10262
+ hoist_defs_of_uses (new_stmt, loop, true);
10267
10263
}
10268
10264
/* These copies are all equivalent. */
10269
10265
if (hoist_p)
0 commit comments