public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/aoliva/heads/testme)] turn -finline-memset-loops into -finline-stringops
Date: Fri, 20 Jan 2023 16:58:50 +0000 (GMT)	[thread overview]
Message-ID: <20230120165850.86B1E3858404@sourceware.org> (raw)

https://gcc.gnu.org/g:3280e71f13d92869c0f750670b3734898f333e20

commit 3280e71f13d92869c0f750670b3734898f333e20
Author: Alexandre Oliva <oliva@gnu.org>
Date:   Fri Jan 20 13:43:14 2023 -0300

    turn -finline-memset-loops into -finline-stringops

Diff:
---
 gcc/builtins.cc                                 |  2 +-
 gcc/common.opt                                  | 28 ++++++++++++++++++++++---
 gcc/doc/invoke.texi                             | 20 +++++++++++-------
 gcc/flag-types.h                                | 11 ++++++++++
 gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c |  2 +-
 5 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 733fe17ede6..b7737678a7d 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -4373,7 +4373,7 @@ try_store_by_multiple_pieces (rtx to, rtx len, unsigned int ctz_len,
       || !can_store_by_pieces (xlenest, builtin_memset_read_str,
 			       &valc, align, true))
     {
-      if (!flag_inline_memset_loops)
+      if (!(flag_inline_stringops & ILSOP_MEMSET))
 	return false;
 
       for (max_bits = orig_max_bits;
diff --git a/gcc/common.opt b/gcc/common.opt
index 5d28f054241..5708823ec7c 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1874,9 +1874,31 @@ finline-atomics
 Common Var(flag_inline_atomics) Init(1) Optimization
 Inline __atomic operations when a lock free instruction sequence is available.
 
-finline-memset-loops
-Common Var(flag_inline_memset_loops) Init(0) Optimization
-Inline memset even if it requires loops.
+finline-stringops=
+Common RejectNegative JoinedOrMissing Var(flag_inline_stringops, ILSOP_ALL) EnumBitSet Enum(ilsop_fn) Init(ILSOP_NONE) Optimization
+-finline-stringops[=all|memcmp|memcpy|memmove|memset]
+Expand supported mem/str operations inline, even if against optimization.
+
+Enum
+Name(ilsop_fn) Type(enum ilsop_fn) UnknownError(unavailable stringop for inlining %qs)
+
+EnumValue
+Enum(ilsop_fn) String(all) Value(ILSOP_ALL)
+
+EnumValue
+Enum(ilsop_fn) String(memcmp) Value(ILSOP_MEMCMP)
+
+EnumValue
+Enum(ilsop_fn) String(memcpy) Value(ILSOP_MEMCPY)
+
+EnumValue
+Enum(ilsop_fn) String(memmove) Value(ILSOP_MEMMOVE)
+
+EnumValue
+Enum(ilsop_fn) String(memset) Value(ILSOP_MEMSET)
+
+EnumVAlue
+Enum(ilsop_fn) String(none) Value(ILSOP_NONE)
 
 fcf-protection
 Common RejectNegative Alias(fcf-protection=,full)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 8f8d52bbeef..4b5717c030b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -11962,14 +11962,18 @@ in its own right.
 Enabled at levels @option{-O1}, @option{-O2}, @option{-O3} and @option{-Os},
 but not @option{-Og}.
 
-@item -finline-memset-loops
-@opindex finline-memset-loops
-Expand @code{memset} calls inline, even when the length is variable or
-big enough as to require looping.  This may enable the compiler to take
-advantage of known alignment and length multipliers, but it will often
-generate code that is less efficient than performant implementations of
-@code{memset}, and grow code size so much that even a less performant
-@code{memset} may run faster due to better use of the code cache.  This
+@item -finline-stringops[=@var{fn}]
+@opindex finline-stringops
+Expand memory and string operations (for now, only @code{memset})
+inline, even when the length is variable or big enough as to require
+looping.  This is most useful along with @option{-ffreestanding} and
+@option{-fno-builtin}.
+
+In some circumstances, it enables the compiler to generate code that
+takes advantage of known alignment and length multipliers, but even then
+it may be less efficient than optimized runtime implementations, and
+grow code size so much that even a less performant but shared
+implementation runs faster due to better use of code caches.  This
 option is disabled by default.
 
 @item -fearly-inlining
diff --git a/gcc/flag-types.h b/gcc/flag-types.h
index 78dbdbe90dd..a9d9eb166b6 100644
--- a/gcc/flag-types.h
+++ b/gcc/flag-types.h
@@ -432,6 +432,17 @@ enum gfc_convert
 };
 
 
+/* Inline String Operations functions.  */
+enum ilsop_fn
+{
+  ILSOP_NONE = 0,
+  ILSOP_MEMSET = 1 << 0,
+  ILSOP_MEMCPY = 1 << 1,
+  ILSOP_MEMMOVE = 1 << 2,
+  ILSOP_MEMCMP = 1 << 3,
+  ILSOP_ALL = -1
+};
+
 /* Control-Flow Protection values.  */
 enum cf_protection_level
 {
diff --git a/gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c b/gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c
index 4de51df006e..8a2f5782b5a 100644
--- a/gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c
+++ b/gcc/testsuite/gcc.dg/torture/inline-mem-set-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-finline-memset-loops -gno-record-gcc-switches -fno-lto" } */
+/* { dg-options "-finline-stringops -fno-lto" } */
 
 void *zero (unsigned long long (*p)[32], int n)
 {

             reply	other threads:[~2023-01-20 16:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 16:58 Alexandre Oliva [this message]
2023-01-20 17:44 Alexandre Oliva
2023-01-20 17:55 Alexandre Oliva
2023-01-20 18:03 Alexandre Oliva
2023-01-20 18:12 Alexandre Oliva
2023-01-20 18:14 Alexandre Oliva
2023-01-20 18:20 Alexandre Oliva
2023-01-20 18:25 Alexandre Oliva
2023-01-20 18:28 Alexandre Oliva
2023-01-20 18:33 Alexandre Oliva
2023-01-20 18:50 Alexandre Oliva
2023-01-20 18:51 Alexandre Oliva
2023-01-20 18:57 Alexandre Oliva
2023-01-20 19:06 Alexandre Oliva
2023-01-20 19:12 Alexandre Oliva
2023-01-20 19:17 Alexandre Oliva
2023-01-20 23:01 Alexandre Oliva
2023-01-27  1:57 Alexandre Oliva
2023-01-27  2:25 Alexandre Oliva
2023-01-27  5:58 Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230120165850.86B1E3858404@sourceware.org \
    --to=aoliva@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).