public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Guenther <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR48172
Date: Thu, 12 May 2011 14:51:00 -0000	[thread overview]
Message-ID: <alpine.LNX.2.00.1105121410470.810@zhemvz.fhfr.qr> (raw)


This fixes PR48172 by properly doing the runtime alias check for
vectorization.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
sofar.

Richard.

2011-05-12  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/48172
	* tree-vect-loop-manip.c (vect_vfa_segment_size): Do not exclude
	the number of iterations from the segment size calculation.
	(vect_create_cond_for_alias_checks): Adjust.

	* gcc.dg/vect/pr48172.c: New testcase.

Index: gcc/tree-vect-loop-manip.c
===================================================================
*** gcc/tree-vect-loop-manip.c	(revision 173693)
--- gcc/tree-vect-loop-manip.c	(working copy)
*************** vect_create_cond_for_align_checks (loop_
*** 2354,2379 ****
     Input:
       DR: The data reference.
       VECT_FACTOR: vectorization factor.
  
     Return an expression whose value is the size of segment which will be
     accessed by DR.  */
  
  static tree
! vect_vfa_segment_size (struct data_reference *dr, tree vect_factor)
  {
!   tree segment_length = fold_build2 (MULT_EXPR, integer_type_node,
! 			             DR_STEP (dr), vect_factor);
! 
    if (vect_supportable_dr_alignment (dr, false)
          == dr_explicit_realign_optimized)
      {
        tree vector_size = TYPE_SIZE_UNIT
  			  (STMT_VINFO_VECTYPE (vinfo_for_stmt (DR_STMT (dr))));
  
!       segment_length = fold_build2 (PLUS_EXPR, integer_type_node,
! 				    segment_length, vector_size);
      }
!   return fold_convert (sizetype, segment_length);
  }
  
  
--- 2354,2384 ----
     Input:
       DR: The data reference.
       VECT_FACTOR: vectorization factor.
+      SCALAR_LOOP_NITERS: number of iterations.
  
     Return an expression whose value is the size of segment which will be
     accessed by DR.  */
  
  static tree
! vect_vfa_segment_size (struct data_reference *dr, int vect_factor,
! 		       tree scalar_loop_niters)
  {
!   tree segment_length;
!   segment_length = size_binop (MULT_EXPR,
! 			       fold_convert (sizetype, DR_STEP (dr)),
! 			       size_int (vect_factor));
!   segment_length = size_binop (MULT_EXPR,
! 			       segment_length,
! 			       fold_convert (sizetype, scalar_loop_niters));
    if (vect_supportable_dr_alignment (dr, false)
          == dr_explicit_realign_optimized)
      {
        tree vector_size = TYPE_SIZE_UNIT
  			  (STMT_VINFO_VECTYPE (vinfo_for_stmt (DR_STMT (dr))));
  
!       segment_length = size_binop (PLUS_EXPR, segment_length, vector_size);
      }
!   return segment_length;
  }
  
  
*************** vect_create_cond_for_alias_checks (loop_
*** 2407,2414 ****
    struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
    VEC (ddr_p, heap) * may_alias_ddrs =
      LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo);
!   tree vect_factor =
!     build_int_cst (integer_type_node, LOOP_VINFO_VECT_FACTOR (loop_vinfo));
  
    ddr_p ddr;
    unsigned int i;
--- 2412,2419 ----
    struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
    VEC (ddr_p, heap) * may_alias_ddrs =
      LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo);
!   int vect_factor = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
!   tree scalar_loop_iters = LOOP_VINFO_NITERS (loop_vinfo);
  
    ddr_p ddr;
    unsigned int i;
*************** vect_create_cond_for_alias_checks (loop_
*** 2460,2467 ****
          vect_create_addr_base_for_vector_ref (stmt_b, cond_expr_stmt_list,
  					      NULL_TREE, loop);
  
!       segment_length_a = vect_vfa_segment_size (dr_a, vect_factor);
!       segment_length_b = vect_vfa_segment_size (dr_b, vect_factor);
  
        if (vect_print_dump_info (REPORT_DR_DETAILS))
  	{
--- 2465,2474 ----
          vect_create_addr_base_for_vector_ref (stmt_b, cond_expr_stmt_list,
  					      NULL_TREE, loop);
  
!       segment_length_a = vect_vfa_segment_size (dr_a, vect_factor,
! 						scalar_loop_iters);
!       segment_length_b = vect_vfa_segment_size (dr_b, vect_factor,
! 						scalar_loop_iters);
  
        if (vect_print_dump_info (REPORT_DR_DETAILS))
  	{
Index: gcc/testsuite/gcc.dg/vect/pr48172.c
===================================================================
*** gcc/testsuite/gcc.dg/vect/pr48172.c	(revision 0)
--- gcc/testsuite/gcc.dg/vect/pr48172.c	(revision 0)
***************
*** 0 ****
--- 1,33 ----
+ /* { dg-do run } */
+ 
+ extern void *memset(void *s, int c, __SIZE_TYPE__ n);
+ extern void abort (void);
+ 
+ #define ASIZE 1028
+ #define HALF (ASIZE/2)
+ 
+ int main() {
+   unsigned int array[ASIZE];
+   int i;
+ 
+   memset(array, 0, sizeof(array));
+ 
+   /* initialize first half of the array */
+   for (i = 0; i < HALF; i++)
+     array[i] = i;
+ 
+   /* fill second half of array in by summing earlier elements of the array
+      gcc 4.5.1 and 4.5.2 incorrectly vectorize this loop!  aray[1025] is left
+      at 0 for ASIZE=1028 */
+   for (i = 0; i < HALF-1; i++)
+     array[HALF+i] = array[2*i] + array[2*i + 1];
+ 
+   /* see if we have any failures */
+   for (i = 0; i < HALF - 1; i++)
+     if (array[HALF+i] != array[2*i] + array[2*i + 1])
+       abort ();
+ 
+   return 0;
+ }
+ 
+ /* { dg-final { cleanup-tree-dump "vect" } } */

                 reply	other threads:[~2011-05-12 12:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.00.1105121410470.810@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).