https://gcc.gnu.org/g:b0f2495634d6c3e40a3a929d2d440eed866dda6d

commit r17-561-gb0f2495634d6c3e40a3a929d2d440eed866dda6d
Author: H.J. Lu <[email protected]>
Date:   Mon May 18 05:48:21 2026 +0800

    x86: Don't inline memmove for -Os
    
    Update ix86_expand_movmem to return false if optimize_function_for_size_p
    returns true to avoid inlining memmove for -Os.
    
    gcc/
    
            PR target/125355
            * config/i386/i386-expand.cc (ix86_expand_movmem): Return false
            for -Os.
    
    gcc/testsuite/
    
            PR target/125355
            * gcc.target/i386/pr125355.c: New test.
    
    Signed-off-by: H.J. Lu <[email protected]>

Diff:
---
 gcc/config/i386/i386-expand.cc           |  2 +-
 gcc/testsuite/gcc.target/i386/pr125355.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index df44a4eb99da..f234f884f9e0 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -10454,7 +10454,7 @@ ix86_expand_movmem (rtx operands[])
 {
   /* Since there are much less registers available in 32-bit mode, don't
      inline movmem in 32-bit mode.  */
-  if (!TARGET_64BIT)
+  if (!TARGET_64BIT || optimize_function_for_size_p (cfun))
     return false;
 
   rtx dst = operands[0];
diff --git a/gcc/testsuite/gcc.target/i386/pr125355.c 
b/gcc/testsuite/gcc.target/i386/pr125355.c
new file mode 100644
index 000000000000..4290cfc56f9b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr125355.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-Os -mtune=generic" } */
+/* { dg-add-options check_function_bodies } */
+/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc').  */
+/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} } 
} */
+
+/*
+**foo:
+**.LFB0:
+**     .cfi_startproc
+**     jmp     memmove
+**     .cfi_endproc
+**...
+*/
+
+#include <stddef.h>
+#include <string.h>
+
+void
+foo (char *d, char *s, size_t n)
+{
+  memmove(d, s, n);
+}

Reply via email to