OK for master and backport to GCC 16? Thanks.
-- H.J. --- 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.
From a7ac9d6381102c765d73c55abea1df28f1196eee Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <[email protected]> Date: Mon, 18 May 2026 05:48:21 +0800 Subject: [PATCH] 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]> --- gcc/config/i386/i386-expand.cc | 2 +- gcc/testsuite/gcc.target/i386/pr125355.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr125355.c diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 036d129ff19..7a686213359 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -10455,7 +10455,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 00000000000..3810e5e121b --- /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 { lp64 } } {^\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); +} -- 2.54.0
