public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR47594: Sign extend constants while translating to Graphite
@ 2011-07-25 17:07 Sebastian Pop
       [not found] ` <alpine.LNX.2.00.1107261020220.810@zhemvz.fhfr.qr>
  0 siblings, 1 reply; 16+ messages in thread
From: Sebastian Pop @ 2011-07-25 17:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: rguenther, tobias, Sebastian Pop

"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  <sebastian.pop@amd.com>

	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  <sebastian.pop@amd.com>
 
+	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  <sebastian.pop@amd.com>
+
 	* 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  <sebastian.pop@amd.com>
 
+	PR middle-end/47594
+	* gfortran.dg/graphite/run-id-pr47594.f90: New.
+
+2011-07-23  Sebastian Pop  <sebastian.pop@amd.com>
+
 	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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-08-02 15:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-25 17:07 [PATCH] Fix PR47594: Sign extend constants while translating to Graphite Sebastian Pop
     [not found] ` <alpine.LNX.2.00.1107261020220.810@zhemvz.fhfr.qr>
2011-07-26 14:33   ` Sebastian Pop
2011-07-26 14:35     ` Richard Guenther
2011-07-26 14:50       ` Sebastian Pop
2011-07-26 15:26         ` Richard Guenther
2011-07-27 16:51           ` Sebastian Pop
2011-07-28  9:31             ` Richard Guenther
2011-07-30  7:37               ` Sebastian Pop
     [not found]                 ` <20110730133351.GA1564@bromo.med.uc.edu>
2011-07-30 17:09                   ` Sebastian Pop
2011-08-02  5:02                     ` [PATCH 0/2] Fix PR47594 Sebastian Pop
2011-08-02  5:03                       ` [PATCH 2/2] Fix PR47594: Build signed niter expressions Sebastian Pop
2011-08-02  7:48                         ` Zdenek Dvorak
2011-08-02  9:51                         ` Richard Guenther
2011-08-02 15:10                           ` Sebastian Pop
2011-08-02  5:03                       ` [PATCH 1/2] Use build_zero_cst or build_one_cst Sebastian Pop
2011-08-02  8:53                         ` Richard Guenther

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).