Hi! As mentioned in the PR, DR_PTR_INFO is for the base of the DR, thus the points-to into in it of course applies to any new SSA_NAME pointers derived from the DR, but the alignment info might not. vect_create_addr_base_for_vector_ref seems to be handling it right, but vect_create_data_ref_ptr didn't, this patch moves the code to handle it from vect_create_addr_base_for_vector_ref into a new helper function (except for the offset/byte_offset case) and uses the new helper in vect_create_data_ref_ptr.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2015-03-18 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/65450 * tree-vect-data-refs.c (vect_duplicate_ssa_name_ptr_info): New function. (vect_create_addr_base_for_vector_ref, vect_create_data_ref_ptr): Use it instead of duplicate_ssa_name_ptr_info. * gfortran.dg/pr65450.f90: New test. --- gcc/tree-vect-data-refs.c.jj 2015-03-10 07:27:43.000000000 +0100 +++ gcc/tree-vect-data-refs.c 2015-03-18 09:54:11.060172717 +0100 @@ -3845,6 +3845,20 @@ vect_get_new_vect_var (tree type, enum v return new_vect_var; } +/* Duplicate ptr info and set alignment/misaligment on NAME from DR. */ + +static void +vect_duplicate_ssa_name_ptr_info (tree name, data_reference *dr, + stmt_vec_info stmt_info) +{ + 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) + mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (name)); + else + set_ptr_info_alignment (SSA_NAME_PTR_INFO (name), align, misalign); +} /* Function vect_create_addr_base_for_vector_ref. @@ -3964,13 +3978,9 @@ vect_create_addr_base_for_vector_ref (gi if (DR_PTR_INFO (dr) && TREE_CODE (addr_base) == SSA_NAME) { - duplicate_ssa_name_ptr_info (addr_base, DR_PTR_INFO (dr)); - unsigned int align = TYPE_ALIGN_UNIT (STMT_VINFO_VECTYPE (stmt_info)); - int misalign = DR_MISALIGNMENT (dr); - if (offset || byte_offset || (misalign == -1)) + vect_duplicate_ssa_name_ptr_info (addr_base, dr, stmt_info); + if (offset || byte_offset) mark_ptr_info_alignment_unknown (SSA_NAME_PTR_INFO (addr_base)); - else - set_ptr_info_alignment (SSA_NAME_PTR_INFO (addr_base), align, misalign); } if (dump_enabled_p ()) @@ -4210,7 +4220,7 @@ vect_create_data_ref_ptr (gimple stmt, t aggr_ptr_init = make_ssa_name (aggr_ptr, vec_stmt); /* Copy the points-to information if it exists. */ if (DR_PTR_INFO (dr)) - duplicate_ssa_name_ptr_info (aggr_ptr_init, DR_PTR_INFO (dr)); + vect_duplicate_ssa_name_ptr_info (aggr_ptr_init, dr, stmt_info); gimple_assign_set_lhs (vec_stmt, aggr_ptr_init); if (pe) { @@ -4253,8 +4263,8 @@ vect_create_data_ref_ptr (gimple stmt, t /* Copy the points-to information if it exists. */ if (DR_PTR_INFO (dr)) { - duplicate_ssa_name_ptr_info (indx_before_incr, DR_PTR_INFO (dr)); - duplicate_ssa_name_ptr_info (indx_after_incr, DR_PTR_INFO (dr)); + vect_duplicate_ssa_name_ptr_info (indx_before_incr, dr, stmt_info); + vect_duplicate_ssa_name_ptr_info (indx_after_incr, dr, stmt_info); } if (ptr_incr) *ptr_incr = incr; @@ -4283,8 +4293,8 @@ vect_create_data_ref_ptr (gimple stmt, t /* Copy the points-to information if it exists. */ if (DR_PTR_INFO (dr)) { - duplicate_ssa_name_ptr_info (indx_before_incr, DR_PTR_INFO (dr)); - duplicate_ssa_name_ptr_info (indx_after_incr, DR_PTR_INFO (dr)); + vect_duplicate_ssa_name_ptr_info (indx_before_incr, dr, stmt_info); + vect_duplicate_ssa_name_ptr_info (indx_after_incr, dr, stmt_info); } if (ptr_incr) *ptr_incr = incr; --- gcc/testsuite/gfortran.dg/pr65450.f90.jj 2015-03-18 11:41:04.478543474 +0100 +++ gcc/testsuite/gfortran.dg/pr65450.f90 2015-03-18 11:40:09.000000000 +0100 @@ -0,0 +1,35 @@ +! PR tree-optimization/65450 +! { dg-do run } +! { dg-additional-options "-mtune=amdfam10" { target x86_64-*-* i?86-*-* } } + +program pr65450 + integer :: n, m, o, i, k + double precision :: u(500,60,3), h(500,60,3) + double precision :: v(500,60) + u = 0 + h = 0 + o = 1 + m = 2 + n = 3 + do k = 1, 50 + v = foo (u(:,:,m)) + u(2:499,1:60,n) = u(2:499,1:60,o)+16.d0 + h(1:500,2:59,n) = h(1:500,2:59,o)-4.d0*v(1:500,2:59)-32.0d0 + i = o + o = m + m = n + n = i + end do + if (abs (v(17, 23) + h(17, 23, 2) + 768.0d0) > 0.5d0) call abort +contains + function foo(a) + double precision :: a(:,:) + double precision :: foo(size(a,dim=1),size(a,dim=2)) + integer :: i, j + i = size(a,dim=1) + j = size(a,dim=2) + foo(2:i-1,1:j) = a(3:i,1:j)-a(1:i-2,1:j) + foo(1,1:j) = 2*(a(2,1:j)-a(1,1:j)) + foo(i,1:j) = 2*(a(i,1:j)-a(i-1,1:j)) + end function foo +end program pr65450 Jakub