diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8cbaeaa3d923097ae02a699280432f7177a06648..7f83513aeb5b7f56a90fefe1195ef300367dabe4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -3,6 +3,10 @@
 	* config/rs6000/tramp.asm: Include config.h.
 	Check __PIC__ or __pic__ macro instead of SHARED.
 
+	PR tree-optimization/33017
+	* tree-data-ref.c (split_constant_offset) <case SSA_NAME>: Don't
+	recurse for pure or const function calls.
+
 2007-09-04  Laurynas Biveinis  <laurynas.biveinis@gmail.com>
 
 	* c-format.c: Include alloc-pool.h.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b68ba679f7453bfe0dd07bfd64d0635c5ff40a0d..b191442349e69035421dc327154525f7d1407c44 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-09-05  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/33017
+	* gcc.dg/pr33017.c: New test.
+
 2007-09-05  Ben Elliston  <bje@au.ibm.com>
 
 	* gcc.target/powerpc/ppu-intrinsics.c: Add test cases for the
diff --git a/gcc/testsuite/gcc.dg/pr33017.c b/gcc/testsuite/gcc.dg/pr33017.c
new file mode 100644
index 0000000000000000000000000000000000000000..851fe71f8607a2f266f2370cc17b720ec71cc3d3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr33017.c
@@ -0,0 +1,30 @@
+/* PR tree-optimization/33017 */
+/* { dg-do run } */
+/* { dg-options "-O2 -ftree-vectorize" } */
+
+extern __SIZE_TYPE__ strlen (const char *);
+extern void abort (void);
+
+char *
+__attribute__((noinline))
+foo (const char *string)
+{
+  int len;
+  static char var[0x104];
+  int off;
+  len = strlen (string);
+  for (off = 0; off < 64; off++)
+    var[len + off + 2] = 0x57;
+  return var;
+}
+
+int
+main (void)
+{
+  char *p = foo ("abcd");
+  int i;
+  for (i = 0; i < 0x104; i++)
+    if (p[i] != ((i >= 6 && i < 70) ? 0x57 : 0))
+      abort ();
+  return 0;
+}
diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index 6ad2e96bea535b52a2d881c6fb8591f9714603b8..720c94d599812c7da1455fa01e048446e896ec62 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -574,7 +574,8 @@ split_constant_offset (tree exp, tree *var, tree *off)
 
 	    if (!TREE_SIDE_EFFECTS (def_stmt_rhs) 
 		&& EXPR_P (def_stmt_rhs)
-		&& !REFERENCE_CLASS_P (def_stmt_rhs))
+		&& !REFERENCE_CLASS_P (def_stmt_rhs)
+		&& !get_call_expr_in (def_stmt_rhs))
 	      {
 		split_constant_offset (def_stmt_rhs, &var0, &off0);
 		var0 = fold_convert (type, var0);