Some refactoring and definitions to use for (unknown) DR_MISALIGNMENT, gcc/ChangeLog:
2017-04-26 Robin Dapp <rd...@linux.vnet.ibm.com> * tree-data-ref.h (struct data_reference): Create DR_HAS_NEGATIVE_STEP. * tree-vectorizer.h (dr_misalignment): Define DR_MISALIGNMENT. * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Use. (vect_update_misalignment_for_peel): Use. (vect_enhance_data_refs_alignment): Use. (vect_no_alias_p): Use. (vect_duplicate_ssa_name_ptr_info): Use. (known_alignment_for_access_p): Use.
diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h index 9003ea5..146853b 100644 --- a/gcc/tree-data-ref.h +++ b/gcc/tree-data-ref.h @@ -145,6 +145,9 @@ struct data_reference #define DR_PTR_INFO(DR) (DR)->alias.ptr_info #define DR_ALIGNED_TO(DR) (DR)->innermost.aligned_to #define DR_INNERMOST(DR) (DR)->innermost +#define DR_HAS_NEGATIVE_STEP(DR) \ + tree_int_cst_compare (DR_STEP (DR), size_zero_node) < 0 + typedef struct data_reference *data_reference_p; diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index aa504b6..9ffae94 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -717,7 +717,7 @@ vect_compute_data_ref_alignment (struct data_reference *dr) loop = LOOP_VINFO_LOOP (loop_vinfo); /* Initialize misalignment to unknown. */ - SET_DR_MISALIGNMENT (dr, -1); + SET_DR_MISALIGNMENT (dr, DR_MISALIGNMENT_UNKNOWN); if (tree_fits_shwi_p (DR_STEP (dr))) misalign = DR_INIT (dr); @@ -947,7 +947,7 @@ vect_update_misalignment_for_peel (struct data_reference *dr, if (known_alignment_for_access_p (dr) && known_alignment_for_access_p (dr_peel)) { - bool negative = tree_int_cst_compare (DR_STEP (dr), size_zero_node) < 0; + bool negative = DR_HAS_NEGATIVE_STEP (dr); int misal = DR_MISALIGNMENT (dr); tree vectype = STMT_VINFO_VECTYPE (stmt_info); misal += negative ? -npeel * dr_size : npeel * dr_size; @@ -957,8 +957,9 @@ vect_update_misalignment_for_peel (struct data_reference *dr, } if (dump_enabled_p ()) - dump_printf_loc (MSG_NOTE, vect_location, "Setting misalignment to -1.\n"); - SET_DR_MISALIGNMENT (dr, -1); + dump_printf_loc (MSG_NOTE, vect_location, "Setting misalignment " \ + "to unknown (-1).\n"); + SET_DR_MISALIGNMENT (dr, DR_MISALIGNMENT_UNKNOWN); } @@ -1526,32 +1527,30 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) { if (known_alignment_for_access_p (dr)) { - unsigned int npeel_tmp; - bool negative = tree_int_cst_compare (DR_STEP (dr), - size_zero_node) < 0; + unsigned int npeel_tmp = 0; + bool negative = DR_HAS_NEGATIVE_STEP (dr); - /* Save info about DR in the hash table. */ vectype = STMT_VINFO_VECTYPE (stmt_info); nelements = TYPE_VECTOR_SUBPARTS (vectype); mis = DR_MISALIGNMENT (dr) / GET_MODE_SIZE (TYPE_MODE ( TREE_TYPE (DR_REF (dr)))); - npeel_tmp = (negative - ? (mis - nelements) : (nelements - mis)) - & (nelements - 1); + if (DR_MISALIGNMENT (dr) != 0) + npeel_tmp = (negative ? (mis - nelements) + : (nelements - mis)) & (nelements - 1); /* For multiple types, it is possible that the bigger type access will have more than one peeling option. E.g., a loop with two types: one of size (vector size / 4), and the other one of size (vector size / 8). Vectorization factor will 8. If both - access are misaligned by 3, the first one needs one scalar + accesses are misaligned by 3, the first one needs one scalar iteration to be aligned, and the second one needs 5. But the first one will be aligned also by peeling 5 scalar iterations, and in that case both accesses will be aligned. Hence, except for the immediate peeling amount, we also want to try to add full vector size, while we don't exceed vectorization factor. - We do this automatically for cost model, since we calculate cost - for every peeling option. */ + We do this automatically for cost model, since we calculate + cost for every peeling option. */ if (unlimited_cost_model (LOOP_VINFO_LOOP (loop_vinfo))) { if (STMT_SLP_TYPE (stmt_info)) @@ -1559,17 +1558,15 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) = (vf * GROUP_SIZE (stmt_info)) / nelements; else possible_npeel_number = vf / nelements; - } - /* Handle the aligned case. We may decide to align some other - access, making DR unaligned. */ - if (DR_MISALIGNMENT (dr) == 0) - { - npeel_tmp = 0; - if (unlimited_cost_model (LOOP_VINFO_LOOP (loop_vinfo))) - possible_npeel_number++; - } + /* NPEEL_TMP is 0 when there is no misalignment, increment + the peeling amount by one in order to ... */ + if (DR_MISALIGNMENT (dr) == 0) + possible_npeel_number++; + } + /* Save info about DR in the hash table. Also include peeling + amounts according to the explanation above. */ for (j = 0; j < possible_npeel_number; j++) { vect_peeling_hash_insert (&peeling_htab, loop_vinfo, @@ -1755,8 +1752,7 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) if (known_alignment_for_access_p (dr0)) { - bool negative = tree_int_cst_compare (DR_STEP (dr0), - size_zero_node) < 0; + bool negative = DR_HAS_NEGATIVE_STEP (dr0); if (!npeel) { /* Since it's known at compile time, compute the number of @@ -3009,7 +3005,7 @@ vect_no_alias_p (struct data_reference *a, struct data_reference *b, /* For negative step, we need to adjust address range by TYPE_SIZE_UNIT bytes, e.g., int a[3] -> a[1] range is [a+4, a+16) instead of [a, a+12) */ - if (tree_int_cst_compare (DR_STEP (a), size_zero_node) < 0) + if (DR_HAS_NEGATIVE_STEP (a)) { tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (a))); seg_a_min = fold_build2 (PLUS_EXPR, TREE_TYPE (seg_a_max), @@ -3020,7 +3016,7 @@ vect_no_alias_p (struct data_reference *a, struct data_reference *b, tree seg_b_min = DR_INIT (b); tree seg_b_max = fold_build2 (PLUS_EXPR, TREE_TYPE (seg_b_min), seg_b_min, segment_length_b); - if (tree_int_cst_compare (DR_STEP (b), size_zero_node) < 0) + if (DR_HAS_NEGATIVE_STEP (b)) { tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (b))); seg_b_min = fold_build2 (PLUS_EXPR, TREE_TYPE (seg_b_max), @@ -4161,7 +4157,7 @@ vect_duplicate_ssa_name_ptr_info (tree name, data_reference *dr, duplicate_ssa_name_ptr_info (name, DR_PTR_INFO (dr)); unsigned int align = TYPE_ALIGN_UNIT (STMT_VINFO_VECTYPE (stmt_info)); int misalign = DR_MISALIGNMENT (dr); - if (misalign == -1) + if (misalign == DR_MISALIGNMENT_UNKNOWN) mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (name)); else set_ptr_info_alignment (SSA_NAME_PTR_INFO (name), align, misalign); diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 12bb904..0d9fe14 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -1012,6 +1012,7 @@ dr_misalignment (struct data_reference *dr) taking into account peeling/versioning if applied. */ #define DR_MISALIGNMENT(DR) dr_misalignment (DR) #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL) +#define DR_MISALIGNMENT_UNKNOWN (-1) /* Return TRUE if the data access is aligned, and FALSE otherwise. */ @@ -1027,7 +1028,7 @@ aligned_access_p (struct data_reference *data_ref_info) static inline bool known_alignment_for_access_p (struct data_reference *data_ref_info) { - return (DR_MISALIGNMENT (data_ref_info) != -1); + return (DR_MISALIGNMENT (data_ref_info) != DR_MISALIGNMENT_UNKNOWN); }