public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] -finline-stringops: check base blksize for memset [PR112784]
@ 2023-12-08 0:57 Alexandre Oliva
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2023-12-08 0:57 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f30e737d3f7a73143eaf818b876aeaa5d9437c3d
commit f30e737d3f7a73143eaf818b876aeaa5d9437c3d
Author: Alexandre Oliva <oliva@gnu.org>
Date: Thu Dec 7 20:12:02 2023 -0300
-finline-stringops: check base blksize for memset [PR112784]
Diff:
---
gcc/builtins.cc | 46 +++++++++++++++++++++-----
gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c | 10 ++++++
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index afa9be51443..40bb4016317 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -4284,6 +4284,31 @@ expand_builtin_memset (tree exp, rtx target, machine_mode mode)
return expand_builtin_memset_args (dest, val, len, target, mode, exp);
}
+/* Check that store_by_pieces allows BITS + LEN (so that we don't
+ expand something too unreasonably long), and every power of 2 in
+ BITS. */
+static bool
+can_store_by_multiple_pieces (unsigned HOST_WIDE_INT bits,
+ by_pieces_constfn constfun,
+ void *constfundata, unsigned int align,
+ bool memsetp,
+ unsigned HOST_WIDE_INT len)
+{
+ if (!can_store_by_pieces (bits + len, constfun, constfundata, align, memsetp))
+ return false;
+
+ /* We start at 2 because we can manage single byte stores even if
+ can_store_by_pieces rejects it. */
+ for (unsigned HOST_WIDE_INT bit = 2;
+ bit && bit < bits;
+ bit <<= 1)
+ if ((bit & bits) != 0
+ && !can_store_by_pieces (bit, constfun, constfundata, align, memsetp))
+ return false;
+
+ return true;
+}
+
/* Try to store VAL (or, if NULL_RTX, VALC) in LEN bytes starting at TO.
Return TRUE if successful, FALSE otherwise. TO is assumed to be
aligned at an ALIGN-bits boundary. LEN must be a multiple of
@@ -4341,7 +4366,9 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
else
/* Huh, max_len < min_len? Punt. See pr100843.c. */
return false;
- if (min_len >= blksize)
+ if (min_len >= blksize
+ && can_store_by_pieces (blksize, builtin_memset_read_str,
+ &valc, align, true))
{
min_len -= blksize;
min_bits = floor_log2 (min_len);
@@ -4367,8 +4394,9 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
happen because of the way max_bits and blksize are related, but
it doesn't hurt to test. */
if (blksize > xlenest
- || !can_store_by_pieces (xlenest, builtin_memset_read_str,
- &valc, align, true))
+ || !can_store_by_multiple_pieces (xlenest - blksize,
+ builtin_memset_read_str,
+ &valc, align, true, blksize))
{
if (!(flag_inline_stringops & ILSOP_MEMSET))
return false;
@@ -4386,17 +4414,17 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
of overflow. */
if (max_bits < orig_max_bits
&& xlenest + blksize >= xlenest
- && can_store_by_pieces (xlenest + blksize,
- builtin_memset_read_str,
- &valc, align, true))
+ && can_store_by_multiple_pieces (xlenest,
+ builtin_memset_read_str,
+ &valc, align, true, blksize))
{
max_loop = true;
break;
}
if (blksize
- && can_store_by_pieces (xlenest,
- builtin_memset_read_str,
- &valc, align, true))
+ && can_store_by_multiple_pieces (xlenest,
+ builtin_memset_read_str,
+ &valc, align, true, 0))
{
max_len += blksize;
min_len += blksize;
diff --git a/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c b/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c
new file mode 100644
index 00000000000..fdfc5b6f28c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-finline-stringops" } */
+
+char buf[3];
+
+int
+f ()
+{
+ __builtin_memset (buf, 'v', 3);
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] -finline-stringops: check base blksize for memset [PR112784]
@ 2023-12-08 1:06 Alexandre Oliva
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2023-12-08 1:06 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d81f3c5282b3a811a249b15aced023d75ae40486
commit d81f3c5282b3a811a249b15aced023d75ae40486
Author: Alexandre Oliva <oliva@gnu.org>
Date: Thu Dec 7 20:12:02 2023 -0300
-finline-stringops: check base blksize for memset [PR112784]
Diff:
---
gcc/builtins.cc | 46 +++++++++++++++++++++-----
gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c | 10 ++++++
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index afa9be51443..40bb4016317 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -4284,6 +4284,31 @@ expand_builtin_memset (tree exp, rtx target, machine_mode mode)
return expand_builtin_memset_args (dest, val, len, target, mode, exp);
}
+/* Check that store_by_pieces allows BITS + LEN (so that we don't
+ expand something too unreasonably long), and every power of 2 in
+ BITS. */
+static bool
+can_store_by_multiple_pieces (unsigned HOST_WIDE_INT bits,
+ by_pieces_constfn constfun,
+ void *constfundata, unsigned int align,
+ bool memsetp,
+ unsigned HOST_WIDE_INT len)
+{
+ if (!can_store_by_pieces (bits + len, constfun, constfundata, align, memsetp))
+ return false;
+
+ /* We start at 2 because we can manage single byte stores even if
+ can_store_by_pieces rejects it. */
+ for (unsigned HOST_WIDE_INT bit = 2;
+ bit && bit < bits;
+ bit <<= 1)
+ if ((bit & bits) != 0
+ && !can_store_by_pieces (bit, constfun, constfundata, align, memsetp))
+ return false;
+
+ return true;
+}
+
/* Try to store VAL (or, if NULL_RTX, VALC) in LEN bytes starting at TO.
Return TRUE if successful, FALSE otherwise. TO is assumed to be
aligned at an ALIGN-bits boundary. LEN must be a multiple of
@@ -4341,7 +4366,9 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
else
/* Huh, max_len < min_len? Punt. See pr100843.c. */
return false;
- if (min_len >= blksize)
+ if (min_len >= blksize
+ && can_store_by_pieces (blksize, builtin_memset_read_str,
+ &valc, align, true))
{
min_len -= blksize;
min_bits = floor_log2 (min_len);
@@ -4367,8 +4394,9 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
happen because of the way max_bits and blksize are related, but
it doesn't hurt to test. */
if (blksize > xlenest
- || !can_store_by_pieces (xlenest, builtin_memset_read_str,
- &valc, align, true))
+ || !can_store_by_multiple_pieces (xlenest - blksize,
+ builtin_memset_read_str,
+ &valc, align, true, blksize))
{
if (!(flag_inline_stringops & ILSOP_MEMSET))
return false;
@@ -4386,17 +4414,17 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
of overflow. */
if (max_bits < orig_max_bits
&& xlenest + blksize >= xlenest
- && can_store_by_pieces (xlenest + blksize,
- builtin_memset_read_str,
- &valc, align, true))
+ && can_store_by_multiple_pieces (xlenest,
+ builtin_memset_read_str,
+ &valc, align, true, blksize))
{
max_loop = true;
break;
}
if (blksize
- && can_store_by_pieces (xlenest,
- builtin_memset_read_str,
- &valc, align, true))
+ && can_store_by_multiple_pieces (xlenest,
+ builtin_memset_read_str,
+ &valc, align, true, 0))
{
max_len += blksize;
min_len += blksize;
diff --git a/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c b/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c
new file mode 100644
index 00000000000..fdfc5b6f28c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-finline-stringops" } */
+
+char buf[3];
+
+int
+f ()
+{
+ __builtin_memset (buf, 'v', 3);
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] -finline-stringops: check base blksize for memset [PR112784]
@ 2023-12-08 0:51 Alexandre Oliva
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2023-12-08 0:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:37b330a3554818abe00f0fcca55df892119db506
commit 37b330a3554818abe00f0fcca55df892119db506
Author: Alexandre Oliva <oliva@gnu.org>
Date: Thu Dec 7 20:12:02 2023 -0300
-finline-stringops: check base blksize for memset [PR112784]
Diff:
---
gcc/builtins.cc | 46 +++++++++++++++++++++-----
gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c | 10 ++++++
2 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 06364024c0b..c9e63502337 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -4284,6 +4284,31 @@ expand_builtin_memset (tree exp, rtx target, machine_mode mode)
return expand_builtin_memset_args (dest, val, len, target, mode, exp);
}
+/* Check that store_by_pieces allows BITS + LEN (so that we don't
+ expand something too unreasonably long), and every power of 2 in
+ BITS. */
+static bool
+can_store_by_multiple_pieces (unsigned HOST_WIDE_INT bits,
+ by_pieces_constfn constfun,
+ void *constfundata, unsigned int align,
+ bool memsetp,
+ unsigned HOST_WIDE_INT len)
+{
+ if (!can_store_by_pieces (bits + len, constfun, constfundata, align, memsetp))
+ return false;
+
+ /* We start at 2 because we can manage single byte stores even if
+ can_store_by_pieces rejects it. */
+ for (unsigned HOST_WIDE_INT bit = 2;
+ bit && bit < bits;
+ bit <<= 1)
+ if ((bit & bits) != 0
+ && !can_store_by_pieces (bit, constfun, constfundata, align, memsetp))
+ return false;
+
+ return true;
+}
+
/* Try to store VAL (or, if NULL_RTX, VALC) in LEN bytes starting at TO.
Return TRUE if successful, FALSE otherwise. TO is assumed to be
aligned at an ALIGN-bits boundary. LEN must be a multiple of
@@ -4341,7 +4366,9 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
else
/* Huh, max_len < min_len? Punt. See pr100843.c. */
return false;
- if (min_len >= blksize)
+ if (min_len >= blksize
+ && can_store_by_pieces (blksize, builtin_memset_read_str,
+ &valc, align, true))
{
min_len -= blksize;
min_bits = floor_log2 (min_len);
@@ -4367,8 +4394,9 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
happen because of the way max_bits and blksize are related, but
it doesn't hurt to test. */
if (blksize > xlenest
- || !can_store_by_pieces (xlenest, builtin_memset_read_str,
- &valc, align, true))
+ || !can_store_by_multiple_pieces (xlenest - blksize,
+ builtin_memset_read_str,
+ &valc, align, true, blksize))
{
if (!(flag_inline_stringops & ILSOP_MEMSET))
return false;
@@ -4386,17 +4414,17 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
of overflow. */
if (max_bits < orig_max_bits
&& xlenest + blksize >= xlenest
- && can_store_by_pieces (xlenest + blksize,
- builtin_memset_read_str,
- &valc, align, true))
+ && can_store_by_multiple_pieces (xlenest,
+ builtin_memset_read_str,
+ &valc, align, true, blksize))
{
max_loop = true;
break;
}
if (blksize
- && can_store_by_pieces (xlenest,
- builtin_memset_read_str,
- &valc, align, true))
+ && can_store_by_multiple_pieces (xlenest,
+ builtin_memset_read_str,
+ &valc, align, true, 0))
{
max_len += blksize;
min_len += blksize;
diff --git a/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c b/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c
new file mode 100644
index 00000000000..fdfc5b6f28c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/inline-mem-cmp-pr112778.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-finline-stringops" } */
+
+char buf[3];
+
+int
+f ()
+{
+ __builtin_memset (buf, 'v', 3);
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-08 1:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08 0:57 [gcc(refs/users/aoliva/heads/testme)] -finline-stringops: check base blksize for memset [PR112784] Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2023-12-08 1:06 Alexandre Oliva
2023-12-08 0:51 Alexandre Oliva
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).