"Bug 47594 - gfortran.dg/vect/vect-5.f90 execution test fails when
compiled with -O2 -fgraphite-identity"
The problem is due to the fact that Graphite generates this loop:
for (scat_3=0;scat_3<=4294967295*scat_1+T_51-1;scat_3++) {
S6(scat_1,scat_3);
}
that has a "-1" encoded as an unsigned "4294967295". This constant
comes from the computation of the number of iterations "M - I" of
the inner loop:
do I = 1, N
do J = I, M
A(J,2) = B(J)
end do
end do
The patch fixes the problem by sign-extending the constants for the
step of a chain of recurrence in scan_tree_for_params_right_scev.
The same patter could occur for multiplication by a scalar, like in
"-1 * N" and so the patch also fixes these cases in
scan_tree_for_params.
Bootstrapped and tested on amd64-linux.
2011-07-23 Sebastian Pop <[email protected]>
PR middle-end/47594
* graphite-sese-to-poly.c (scan_tree_for_params_right_scev): Sign
extend constants.
(scan_tree_for_params): Same.
* gfortran.dg/graphite/run-id-pr47594.f90: New.
---
gcc/ChangeLog | 7 ++++
gcc/graphite-sese-to-poly.c | 26 ++++++++++++--
gcc/testsuite/ChangeLog | 5 +++
.../gfortran.dg/graphite/run-id-pr47594.f90 | 35 ++++++++++++++++++++
4 files changed, 69 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/graphite/run-id-pr47594.f90
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 65676cb..f7e2f7d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2011-07-23 Sebastian Pop <[email protected]>
+ PR middle-end/47594
+ * graphite-sese-to-poly.c (scan_tree_for_params_right_scev): Sign
+ extend constants.
+ (scan_tree_for_params): Same.
+
+2011-07-23 Sebastian Pop <[email protected]>
+
* tree-ssa-loop-manip.c (canonicalize_loop_ivs): Build an unsigned
iv only when the largest type is unsigned. Do not call
lang_hooks.types.type_for_size.
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 7e23c9d..5c9e984 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -633,7 +633,11 @@ scan_tree_for_params_right_scev (sese s, tree e, int var,
gcc_assert (TREE_CODE (e) == INTEGER_CST);
mpz_init (val);
- tree_int_to_gmp (e, val);
+
+ /* Necessary to not get "-1 = 2^n - 1". */
+ mpz_set_double_int
+ (val, double_int_sext (tree_to_double_int (e),
+ TYPE_PRECISION (TREE_TYPE (e))), false);
add_value_to_dim (l, expr, val);
mpz_clear (val);
}
@@ -729,9 +733,16 @@ scan_tree_for_params (sese s, tree e,
ppl_Linear_Expression_t c,
if (c)
{
mpz_t val;
- gcc_assert (host_integerp (TREE_OPERAND (e, 1), 0));
+ tree cst = TREE_OPERAND (e, 1);
+
+ gcc_assert (host_integerp (cst, 0));
mpz_init (val);
- tree_int_to_gmp (TREE_OPERAND (e, 1), val);
+
+ /* Necessary to not get "-1 = 2^n - 1". */
+ mpz_set_double_int
+ (val, double_int_sext (tree_to_double_int (cst),
+ TYPE_PRECISION (TREE_TYPE (cst))),
false);
+
mpz_mul (val, val, k);
scan_tree_for_params (s, TREE_OPERAND (e, 0), c, val);
mpz_clear (val);
@@ -744,9 +755,16 @@ scan_tree_for_params (sese s, tree e,
ppl_Linear_Expression_t c,
if (c)
{
mpz_t val;
+ tree cst = TREE_OPERAND (e, 0);
+
gcc_assert (host_integerp (TREE_OPERAND (e, 0), 0));
mpz_init (val);
- tree_int_to_gmp (TREE_OPERAND (e, 0), val);
+
+ /* Necessary to not get "-1 = 2^n - 1". */
+ mpz_set_double_int
+ (val, double_int_sext (tree_to_double_int (cst),
+ TYPE_PRECISION (TREE_TYPE (cst))),
false);
+
mpz_mul (val, val, k);
scan_tree_for_params (s, TREE_OPERAND (e, 1), c, val);
mpz_clear (val);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1f93f4c..b7c2be3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2011-07-23 Sebastian Pop <[email protected]>
+ PR middle-end/47594
+ * gfortran.dg/graphite/run-id-pr47594.f90: New.
+
+2011-07-23 Sebastian Pop <[email protected]>
+
PR middle-end/47653
* gcc.dg/graphite/run-id-pr47653.c: New.
* gcc.dg/graphite/interchange-3.c: Do not use unsigned types for
diff --git a/gcc/testsuite/gfortran.dg/graphite/run-id-pr47594.f90
b/gcc/testsuite/gfortran.dg/graphite/run-id-pr47594.f90
new file mode 100644
index 0000000..7f36fc6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/graphite/run-id-pr47594.f90
@@ -0,0 +1,35 @@
+! { dg-options "-O2 -fgraphite-identity" }
+
+ Subroutine foo (N, M)
+ Integer N
+ Integer M
+ integer A(8,16)
+ integer B(8)
+
+ B = (/ 2, 3, 5, 7, 11, 13, 17, 23 /)
+
+ do I = 1, N
+ do J = I, M
+ A(J,2) = B(J)
+ end do
+ end do
+
+ do I = 1, N
+ do J = I, M
+ if (A(J,2) /= B(J)) then
+ call abort ()
+ endif
+ end do
+ end do
+
+ Return
+ end
+
+
+ program main
+
+ Call foo (16, 8)
+
+ stop
+ end
+
--
1.7.4.1