PING [PATCH] x86: Inline strncmp only with -minline-all-stringops

H.J. Lu hjl.tools@gmail.com
Wed Aug 19 13:25:38 GMT 2020


On Wed, Jul 15, 2020 at 10:42:27AM -0700, H.J. Lu wrote:
> Expand strncmp to "repz cmpsb" only with -minline-all-stringops since
> "repz cmpsb" can be much slower than strncmp function implemented with
> vector instructions, see
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
> 
> gcc/
> 
> 	PR target/95458
> 	* config/i386/i386-expand.c (ix86_expand_cmpstrn_or_cmpmem):
> 	Return false for -mno-inline-all-stringops.
> 
> gcc/testsuite/
> 
> 	PR target/95458
> 	* gcc.target/i386/pr95458-1.c: New test.
> 	* gcc.target/i386/pr95458-2.c: Likewise.

Expand strncmp to "repz cmpsb" only with -minline-all-stringops since
"repz cmpsb" can be much slower than strncmp function implemented with
vector instructions, see

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052

gcc/

	PR target/95458
	* config/i386/i386.md (cmpstrnsi): Expand only with
	TARGET_INLINE_ALL_STRINGOPS.

gcc/testsuite/

	PR target/95458
	* gcc.target/i386/pr95458-1.c: New test.
	* gcc.target/i386/pr95458-2.c: Likewise.
---
 gcc/config/i386/i386.md                   |  8 +++++++-
 gcc/testsuite/gcc.target/i386/pr95458-1.c | 11 +++++++++++
 gcc/testsuite/gcc.target/i386/pr95458-2.c |  7 +++++++
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr95458-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr95458-2.c

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index fb677e17817..f3fbed81c4a 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -18007,7 +18007,13 @@ (define_expand "cmpstrnsi"
 {
   rtx addr1, addr2, countreg, align, out;
 
-  if (optimize_insn_for_size_p () && !TARGET_INLINE_ALL_STRINGOPS)
+  /* Expand strncmp only with -minline-all-stringops since
+     "repz cmpsb" can be much slower than strncmp functions
+     implemented with vector instructions, see
+
+     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
+   */
+  if (!TARGET_INLINE_ALL_STRINGOPS)
     FAIL;
 
   /* Can't use this if the user has appropriated ecx, esi or edi.  */
diff --git a/gcc/testsuite/gcc.target/i386/pr95458-1.c b/gcc/testsuite/gcc.target/i386/pr95458-1.c
new file mode 100644
index 00000000000..231a4787dce
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr95458-1.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -minline-all-stringops" } */
+
+int
+func (char *d, unsigned int l)
+{
+  return __builtin_strncmp (d, "foo", l) ? 1 : 2;
+}
+
+/* { dg-final { scan-assembler-not "call\[\\t \]*_?strncmp" } } */
+/* { dg-final { scan-assembler "cmpsb" } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr95458-2.c b/gcc/testsuite/gcc.target/i386/pr95458-2.c
new file mode 100644
index 00000000000..1a620444770
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr95458-2.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mno-inline-all-stringops" } */
+
+#include "pr95458-1.c"
+
+/* { dg-final { scan-assembler "call\[\\t \]*_?strncmp" } } */
+/* { dg-final { scan-assembler-not "cmpsb" } } */
-- 
2.26.2



More information about the Gcc-patches mailing list