On Mon, May 18, 2026 at 2:11 PM Richard Biener <[email protected]> wrote: > > On Mon, May 18, 2026 at 8:08 AM H.J. Lu <[email protected]> wrote: > > > > On Mon, May 18, 2026 at 1:56 PM Richard Biener > > <[email protected]> wrote: > > > > > > On Mon, May 18, 2026 at 4:25 AM Liu, Hongtao <[email protected]> > > > wrote: > > > > > > > > > > > > > > > > > -----Original Message----- > > > > > From: H.J. Lu <[email protected]> > > > > > Sent: Monday, May 18, 2026 5:52 AM > > > > > To: GCC Patches <[email protected]>; Uros Bizjak > > > > > <[email protected]>; Liu, Hongtao <[email protected]> > > > > > Subject: [PATCH] x86: Don't inline memmove for -Os > > > > > > > > > > OK for master and backport to GCC 16? > > > > Ok. > > > > > > > > > > Thanks. > > > > > > > > > > -- > > > > > H.J. > > > > > --- > > > > > Update ix86_expand_movmem to return false if > > > > > optimize_function_for_size_p > > > > > returns true to avoid inlining memmove for -Os. > > > > > > I think you should use optimize_insn_for_size_p instead. > > > > Do you have a testcase to show that it makes a difference? > > It will make a difference with PGO, cold code should be optimized for size. > Another testcase would be -O2 with a path ending in abort(), so prediction > makes it cold. >
Here is the patch. OK for master and backport to GCC 16? Thanks. -- H.J. --- Replace optimize_function_for_size_p with optimize_insn_for_size_p in ix86_expand_movmem to avoid inlining cold memmove call. gcc/ PR target/125355 * config/i386/i386-expand.cc (ix86_expand_movmem): Replace optimize_function_for_size_p with optimize_insn_for_size_p. gcc/testsuite/ PR target/125355 * gcc.target/i386/pr125355-2.c: New test.
From 1310fc9a62d213b22977e4c8499a4d7e83219e91 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <[email protected]> Date: Mon, 18 May 2026 14:46:57 +0800 Subject: [PATCH] x86: Don't inline cold memmove call Replace optimize_function_for_size_p with optimize_insn_for_size_p in ix86_expand_movmem to avoid inlining cold memmove call. gcc/ PR target/125355 * config/i386/i386-expand.cc (ix86_expand_movmem): Replace optimize_function_for_size_p with optimize_insn_for_size_p. gcc/testsuite/ PR target/125355 * gcc.target/i386/pr125355-2.c: New test. Signed-off-by: H.J. Lu <[email protected]> --- gcc/config/i386/i386-expand.cc | 2 +- gcc/testsuite/gcc.target/i386/pr125355-2.c | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr125355-2.c diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 4e254cddf3f..6c23b15bf98 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 || optimize_function_for_size_p (cfun)) + if (!TARGET_64BIT || optimize_insn_for_size_p ()) return false; rtx dst = operands[0]; diff --git a/gcc/testsuite/gcc.target/i386/pr125355-2.c b/gcc/testsuite/gcc.target/i386/pr125355-2.c new file mode 100644 index 00000000000..b198c7debc8 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr125355-2.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mtune=generic" } */ +/* { dg-add-options check_function_bodies } */ +/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc'). */ +/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} } } */ + +/* +**foo.cold: +**... +** call memmove +** call abort +** .cfi_endproc +**... +*/ + +#include <stddef.h> +#include <string.h> + +void +foo (char *d, char *s, size_t n) +{ + if (n < 80) + { + memmove (d, s, n); + __builtin_abort (); + } +} -- 2.54.0
