return res;
}
-/* Return the misalignment of DR_INFO accessed in VECTYPE. */
+/* Return the misalignment of DR_INFO accessed in VECTYPE with OFFSET
+ applied. */
int
-dr_misalignment (dr_vec_info *dr_info, tree vectype)
+dr_misalignment (dr_vec_info *dr_info, tree vectype, poly_int64 offset)
{
HOST_WIDE_INT diff = 0;
/* Alignment is only analyzed for the first element of a DR group,
targetm.vectorize.preferred_vector_alignment (vectype)))
return DR_MISALIGNMENT_UNKNOWN;
- /* If this is a backward running DR then first access in the larger
- vectype actually is N-1 elements before the address in the DR.
- Adjust misalign accordingly. */
- poly_int64 misalignment = misalign + diff;
- if (tree_int_cst_sgn (DR_STEP (dr_info->dr)) < 0)
- misalignment += ((TYPE_VECTOR_SUBPARTS (vectype) - 1)
- * -TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
+ /* Apply the offset from the DR group start and the externally supplied
+ offset which can for example result from a negative stride access. */
+ poly_int64 misalignment = misalign + diff + offset;
/* vect_compute_data_ref_alignment will have ensured that target_alignment
is constant and otherwise set misalign to DR_MISALIGNMENT_UNKNOWN. */
int misalignment;
unsigned HOST_WIDE_INT alignment;
+ bool negative = tree_int_cst_compare (DR_STEP (dr_info->dr),
+ size_zero_node) < 0;
+ poly_int64 off = 0;
+ if (negative)
+ off = ((TYPE_VECTOR_SUBPARTS (vectype) - 1)
+ * -TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
+
if (npeel == 0)
- misalignment = dr_misalignment (dr_info, vectype);
+ misalignment = dr_misalignment (dr_info, vectype, off);
else if (dr_info == dr0_info
|| vect_dr_aligned_if_peeled_dr_is (dr_info, dr0_info))
misalignment = 0;
misalignment = DR_MISALIGNMENT_UNKNOWN;
else
{
- misalignment = dr_misalignment (dr_info, vectype);
+ misalignment = dr_misalignment (dr_info, vectype, off);
misalignment += npeel * TREE_INT_CST_LOW (DR_STEP (dr_info->dr));
misalignment &= alignment - 1;
}
*/
unsigned int target_align =
DR_TARGET_ALIGNMENT (dr_info).to_constant ();
- unsigned int dr_size = vect_get_scalar_dr_size (dr_info);
- unsigned int mis = dr_misalignment (dr_info, vectype);
+ unsigned HOST_WIDE_INT dr_size = vect_get_scalar_dr_size (dr_info);
+ poly_int64 off = 0;
+ if (negative)
+ off = (TYPE_VECTOR_SUBPARTS (vectype) - 1) * -dr_size;
+ unsigned int mis = dr_misalignment (dr_info, vectype, off);
mis = negative ? mis : -mis;
if (mis != 0)
npeel_tmp = (mis & (target_align - 1)) / dr_size;
updating DR_MISALIGNMENT values. The peeling factor is the
vectorization factor minus the misalignment as an element
count. */
+ tree vectype = STMT_VINFO_VECTYPE (stmt_info);
+ poly_int64 off = 0;
+ if (negative)
+ off = ((TYPE_VECTOR_SUBPARTS (vectype) - 1)
+ * -TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
unsigned int mis
- = dr_misalignment (dr0_info, STMT_VINFO_VECTYPE (stmt_info));
+ = dr_misalignment (dr0_info, vectype, off);
mis = negative ? mis : -mis;
/* If known_alignment_for_access_p then we have set
DR_MISALIGNMENT which is only done if we know it at compiler
FOR_EACH_VEC_ELT (datarefs, i, dr)
{
dr_vec_info *dr_info = loop_vinfo->lookup_dr (dr);
- stmt_vec_info stmt_info = dr_info->stmt;
- tree vectype = STMT_VINFO_VECTYPE (stmt_info);
- int misalignment;
- if ((misalignment = dr_misalignment (dr_info, vectype)) == 0
- || !vect_relevant_for_alignment_p (dr_info))
+ if (!vect_relevant_for_alignment_p (dr_info))
continue;
+ stmt_vec_info stmt_info = dr_info->stmt;
if (STMT_VINFO_STRIDED_P (stmt_info))
{
do_versioning = false;
break;
}
+ tree vectype = STMT_VINFO_VECTYPE (stmt_info);
+ bool negative = tree_int_cst_compare (DR_STEP (dr),
+ size_zero_node) < 0;
+ poly_int64 off = 0;
+ if (negative)
+ off = ((TYPE_VECTOR_SUBPARTS (vectype) - 1)
+ * -TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
+ int misalignment;
+ if ((misalignment = dr_misalignment (dr_info, vectype, off)) == 0)
+ continue;
+
enum dr_alignment_support supportable_dr_alignment
= vect_supportable_dr_alignment (loop_vinfo, dr_info, vectype,
misalignment);
*poffset = ((-TYPE_VECTOR_SUBPARTS (vectype) + 1)
* TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (vectype))));
- int misalignment = dr_misalignment (dr_info, vectype);
+ int misalignment = dr_misalignment (dr_info, vectype, *poffset);
alignment_support_scheme
= vect_supportable_dr_alignment (vinfo, dr_info, vectype, misalignment);
if (alignment_support_scheme != dr_aligned
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"negative step but alignment required.\n");
- return VMAT_ELEMENTWISE;
*poffset = 0;
+ return VMAT_ELEMENTWISE;
}
if (vls_type == VLS_STORE_INVARIANT)
}
else
{
- *misalignment = dr_misalignment (first_dr_info, vectype);
+ *misalignment = dr_misalignment (first_dr_info, vectype, *poffset);
*alignment_support_scheme
= vect_supportable_dr_alignment (vinfo, first_dr_info, vectype,
*misalignment);
else
*memory_access_type = VMAT_CONTIGUOUS;
*misalignment = dr_misalignment (STMT_VINFO_DR_INFO (stmt_info),
- vectype);
+ vectype, *poffset);
*alignment_support_scheme
= vect_supportable_dr_alignment (vinfo,
STMT_VINFO_DR_INFO (stmt_info),
align = known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
if (alignment_support_scheme == dr_aligned)
- {
- gcc_assert (aligned_access_p (first_dr_info, vectype));
- misalign = 0;
- }
+ misalign = 0;
else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
{
align = dr_alignment (vect_dr_behavior (vinfo, first_dr_info));
? dataref_offset
: build_int_cst (ref_type, 0));
if (alignment_support_scheme == dr_aligned)
- gcc_assert (aligned_access_p (first_dr_info, vectype));
+ ;
else
TREE_TYPE (data_ref)
= build_aligned_type (TREE_TYPE (data_ref),
align =
known_alignment (DR_TARGET_ALIGNMENT (first_dr_info));
if (alignment_support_scheme == dr_aligned)
- {
- gcc_assert (aligned_access_p (first_dr_info, vectype));
- misalign = 0;
- }
+ misalign = 0;
else if (misalignment == DR_MISALIGNMENT_UNKNOWN)
{
align = dr_alignment