[patch 4/4 v4] Allow loop prefetch code to speculatively prefetch non constant steps

Christian Borntraeger borntraeger@de.ibm.com
Thu May 20 13:38:00 GMT 2010


Am Donnerstag 20 Mai 2010 00:25:48 schrieb H.J. Lu:
> This caused:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44203

H.J.,

Can you verify the following patch?


2010-05-20  Christian Borntraeger  <borntraeger@de.ibm.com>

        PR 44203
        * gcc/tree-ssa-loop-prefetch.c: Fix logic for step calculation to
        match the original (and intended) behaviour before r159557.  This
        changeset changed a=a+b*c to a=(a+b)*b which was obviously wrong
        in two ways. 

Index: gcc/tree-ssa-loop-prefetch.c
===================================================================
*** gcc/tree-ssa-loop-prefetch.c.orig
--- gcc/tree-ssa-loop-prefetch.c
*************** idx_analyze_ref (tree base, tree *index,
*** 425,449 ****
        ibase = build_int_cst (TREE_TYPE (ibase), 0);
      }
  
-   if (*ar_data->step == NULL_TREE)
-     *ar_data->step = step;
-   else
-     *ar_data->step = fold_build2 (PLUS_EXPR, sizetype,
- 				  fold_convert (sizetype, *ar_data->step),
- 				  fold_convert (sizetype, step));
    if (TREE_CODE (base) == ARRAY_REF)
      {
        stepsize = array_ref_element_size (base);
        if (!cst_and_fits_in_hwi (stepsize))
  	return false;
        imult = int_cst_value (stepsize);
! 
!       *ar_data->step = fold_build2 (MULT_EXPR, sizetype,
! 				    fold_convert (sizetype, *ar_data->step),
! 				    fold_convert (sizetype, step));
        idelta *= imult;
      }
  
    *ar_data->delta += idelta;
    *index = ibase;
  
--- 425,448 ----
        ibase = build_int_cst (TREE_TYPE (ibase), 0);
      }
  
    if (TREE_CODE (base) == ARRAY_REF)
      {
        stepsize = array_ref_element_size (base);
        if (!cst_and_fits_in_hwi (stepsize))
  	return false;
        imult = int_cst_value (stepsize);
!       step = fold_build2 (MULT_EXPR, sizetype,
! 			  fold_convert (sizetype, step),
! 			  fold_convert (sizetype, stepsize));
        idelta *= imult;
      }
  
+   if (*ar_data->step == NULL_TREE)
+     *ar_data->step = step;
+   else
+     *ar_data->step = fold_build2 (PLUS_EXPR, sizetype,
+ 				  fold_convert (sizetype, *ar_data->step),
+ 				  fold_convert (sizetype, step));
    *ar_data->delta += idelta;
    *index = ibase;
  



More information about the Gcc-patches mailing list