tree-optimization/105786 - avoid strlen replacement for pointers
authorRichard Biener <rguenther@suse.de>
Wed, 1 Jun 2022 12:13:01 +0000 (14:13 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 2 Jun 2022 08:14:04 +0000 (10:14 +0200)
This avoids matching strlen to a pointer result, avoiding ICEing
because of an integer adjustment using PLUS_EXPR on pointers.

2022-06-01  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105786
* tree-loop-distribution.cc
(loop_distribution::transform_reduction_loop): Only do strlen
replacement for integer type reductions.

* gcc.dg/torture/pr105786.c: New testcase.

(cherry picked from commit 57a8fb92ac4161ebbf9381b009e8c5af843e3e5f)

gcc/testsuite/gcc.dg/torture/pr105786.c [new file with mode: 0644]
gcc/tree-loop-distribution.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr105786.c b/gcc/testsuite/gcc.dg/torture/pr105786.c
new file mode 100644 (file)
index 0000000..64aacf7
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+void sink(const char*);
+static const char *a;
+int main()
+{
+  const char *b = a;
+  for (int i = 0; i < 2; ++i)
+    while (*b++)
+      ;
+  sink(b);
+  return 0;
+}
index db6e909..086b59c 100644 (file)
@@ -3658,6 +3658,7 @@ loop_distribution::transform_reduction_loop (loop_p loop)
   /* Handle strlen like loops.  */
   if (store_dr == NULL
       && integer_zerop (pattern)
+      && INTEGRAL_TYPE_P (TREE_TYPE (reduction_var))
       && TREE_CODE (reduction_iv.base) == INTEGER_CST
       && TREE_CODE (reduction_iv.step) == INTEGER_CST
       && integer_onep (reduction_iv.step))