From a1596edc4b46231e18e86e225fb19ecb0a1437e1 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <pop@cri.ensmp.fr>
Date: Sun, 21 Aug 2005 12:48:23 +0200
Subject: [PATCH] re PR tree-optimization/23434 (ICE: Segmentation fault
 compiling gsl1.5 at -O2)

	PR tree-optimization/23434
        * tree-ssa-loop-niter.c (proved_non_wrapping_p): Give up when
        the iteration bound is not an INTEGER_CST.

From-SVN: r103315
---
 gcc/ChangeLog                           |  6 ++++++
 gcc/testsuite/gcc.dg/tree-ssa/pr23434.c | 19 +++++++++++++++++++
 gcc/tree-ssa-loop-niter.c               |  4 ++++
 3 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr23434.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 29c53163ef6e..6e2b4d8ed702 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-21  Sebastian Pop  <pop@cri.ensmp.fr>
+
+	PR tree-optimization/23434
+        * tree-ssa-loop-niter.c (proved_non_wrapping_p): Give up when
+        the iteration bound is not an INTEGER_CST.
+
 2005-08-21  Dorit Nuzman  <dorit@il.ibm.com>
 
 	* tree-vect-transform.c (get_initial_def_for_reduction): Set
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr23434.c b/gcc/testsuite/gcc.dg/tree-ssa/pr23434.c
new file mode 100644
index 000000000000..a21b955666e6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr23434.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+cblas_csyr2k (int N, void *A, int lda, float *B, int ldb, float *C, int k)
+{
+  int i, j;
+  for (;; k ++)
+    {
+      for (i = 0; i < N; i ++)
+	{
+	  float t = ((float * ) A) [i];
+	  for (j = i; j < N; j ++)
+	    {
+	      C [i + j] = B [ldb] * ((float *) A) [k];
+	      C [lda] = 0 ;
+	    }
+	}
+    }
+}
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index fc5491b857e4..a8e4737633d5 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1653,6 +1653,10 @@ proved_non_wrapping_p (tree at_stmt,
   else
     valid_niter = fold_convert (TREE_TYPE (bound), valid_niter);
 
+  /* Give up if BOUND was not folded to an INTEGER_CST, as in PR23434.  */
+  if (TREE_CODE (bound) != INTEGER_CST)
+    return false;
+
   /* After the statement niter_bound->at_stmt we know that anything is
      executed at most BOUND times.  */
   if (at_stmt && stmt_dominates_stmt_p (niter_bound->at_stmt, at_stmt))
-- 
GitLab