public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/105786 - avoid strlen replacement for pointers
@ 2022-06-01 13:17 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-01 13:17 UTC (permalink / raw)
  To: gcc-patches

This avoids matching strlen to a pointer result, avoiding ICEing
because of an integer adjustment using PLUS_EXPR on pointers.

Boostrapped and tested on x86_64-unknown-linux-gnu, pushed.

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.
---
 gcc/testsuite/gcc.dg/torture/pr105786.c | 13 +++++++++++++
 gcc/tree-loop-distribution.cc           |  1 +
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr105786.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr105786.c b/gcc/testsuite/gcc.dg/torture/pr105786.c
new file mode 100644
index 00000000000..64aacf74b0a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr105786.c
@@ -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;
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index db6e9096a86..086b59ca2be 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -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))
-- 
2.35.3

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

* [PATCH] tree-optimization/105786 - avoid strlen replacement for pointers
@ 2022-06-01 13:17 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-01 13:17 UTC (permalink / raw)
  To: gcc-patches

This avoids matching strlen to a pointer result, avoiding ICEing
because of an integer adjustment using PLUS_EXPR on pointers.

Boostrapped and tested on x86_64-unknown-linux-gnu, pushed.

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.
---
 gcc/testsuite/gcc.dg/torture/pr105786.c | 13 +++++++++++++
 gcc/tree-loop-distribution.cc           |  1 +
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr105786.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr105786.c b/gcc/testsuite/gcc.dg/torture/pr105786.c
new file mode 100644
index 00000000000..64aacf74b0a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr105786.c
@@ -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;
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index db6e9096a86..086b59ca2be 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -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))
-- 
2.35.3

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

* [PATCH] tree-optimization/105786 - avoid strlen replacement for pointers
@ 2022-06-01 13:17 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-06-01 13:17 UTC (permalink / raw)
  To: gcc-patches

This avoids matching strlen to a pointer result, avoiding ICEing
because of an integer adjustment using PLUS_EXPR on pointers.

Boostrapped and tested on x86_64-unknown-linux-gnu, pushed.

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.
---
 gcc/testsuite/gcc.dg/torture/pr105786.c | 13 +++++++++++++
 gcc/tree-loop-distribution.cc           |  1 +
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr105786.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr105786.c b/gcc/testsuite/gcc.dg/torture/pr105786.c
new file mode 100644
index 00000000000..64aacf74b0a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr105786.c
@@ -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;
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index db6e9096a86..086b59ca2be 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -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))
-- 
2.35.3

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

end of thread, other threads:[~2022-06-01 13:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01 13:17 [PATCH] tree-optimization/105786 - avoid strlen replacement for pointers Richard Biener
  -- strict thread matches above, loose matches on Subject: below --
2022-06-01 13:17 Richard Biener
2022-06-01 13:17 Richard Biener

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