This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Dependence analysis fixes
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: sebastian dot pop at inria dot fr
- Date: Wed, 11 Apr 2007 00:47:55 +0200
- Subject: [patch] Dependence analysis fixes
Hello,
this patch fixes two problems exposed in dependence analysis during my
work on prefetching improvements:
1) sometimes, we may try to build a polynomial chrec with zero step
(e.g., due to casting it to shorter type, or in multiplication if the
operation overflows). This leads to ICE in dependence analysis, as
it expects that this is not the case. Fixed by avoiding creating
such chrecs in build_polynomial_chrec.
2) add_multivariate_self_dist may produce distance vectors that are
lexicographically negative. This seems to be an error, since
on all other places we force the vectors to be positive.
Also, for {{0, +, 4}_1, +, 6}_2, we would return distance vector
(6,-4). However, we access the same location already in distance
(3,-2). Fixed by dividing the elements of the vector by their
gcd.
Bootstrapped & regtested on i686.
Zdenek
* tree-chrec.h (build_polynomial_chrec): Do not create chrecs with
zero step.
* tree-data-ref.c (add_multivariate_self_dist): Force the distance
vector to be positive.
Index: tree-chrec.h
===================================================================
*** tree-chrec.h (revision 123691)
--- tree-chrec.h (working copy)
*************** build_polynomial_chrec (unsigned loop_nu
*** 99,104 ****
--- 99,107 ----
gcc_assert (TREE_TYPE (left) == TREE_TYPE (right));
+ if (integer_zerop (right))
+ return left;
+
return build3 (POLYNOMIAL_CHREC, TREE_TYPE (left),
build_int_cst (NULL_TREE, loop_num), left, right);
}
Index: tree-data-ref.c
===================================================================
*** tree-data-ref.c (revision 123691)
--- tree-data-ref.c (working copy)
*************** add_multivariate_self_dist (struct data_
*** 3857,3862 ****
--- 3857,3863 ----
tree c_1 = CHREC_LEFT (c_2);
tree c_0 = CHREC_LEFT (c_1);
lambda_vector dist_v;
+ int v1, v2, cd;
/* Polynomials with more than 2 variables are not handled yet. */
if (TREE_CODE (c_0) != INTEGER_CST)
*************** add_multivariate_self_dist (struct data_
*** 3870,3877 ****
/* For "{{0, +, 2}_1, +, 3}_2" the distance vector is (3, -2). */
dist_v = lambda_vector_new (DDR_NB_LOOPS (ddr));
! dist_v[x_1] = int_cst_value (CHREC_RIGHT (c_2));
! dist_v[x_2] = -int_cst_value (CHREC_RIGHT (c_1));
save_dist_v (ddr, dist_v);
add_outer_distances (ddr, dist_v, x_1);
--- 3871,3890 ----
/* For "{{0, +, 2}_1, +, 3}_2" the distance vector is (3, -2). */
dist_v = lambda_vector_new (DDR_NB_LOOPS (ddr));
! v1 = int_cst_value (CHREC_RIGHT (c_1));
! v2 = int_cst_value (CHREC_RIGHT (c_2));
! cd = gcd (v1, v2);
! v1 /= cd;
! v2 /= cd;
!
! if (v2 < 0)
! {
! v2 = -v2;
! v1 = -v1;
! }
!
! dist_v[x_1] = v2;
! dist_v[x_2] = -v1;
save_dist_v (ddr, dist_v);
add_outer_distances (ddr, dist_v, x_1);