On Wed, Jul 30, 2025 at 11:45 AM H.J. Lu <hjl.to...@gmail.com> wrote:
>
> commit 4c80062d7b8c272e2e193b8074a8440dbb4fe588
> Author: H.J. Lu <hjl.to...@gmail.com>
> Date:   Sun May 25 07:40:29 2025 +0800
>
>     x86: Enable *mov<mode>_(and|or) only for -Oz
>
> disabled transformation from "movq $-1,reg" to "pushq $-1; popq reg" for
> -Oz.  But for legacy integer registers, the former is 4 bytes and the
> latter is 3 bytes.  Enable such transformation for -Oz.
Ok.
>
> gcc/
>
>         PR target/120427
>         * config/i386/i386.md (peephole2): Transform "movq $-1,reg" to
>         "pushq $-1; popq reg" for -Oz if reg is a legacy integer register.
>
> gcc/testsuite/
>
>         PR target/120427
>         * gcc.target/i386/pr120427-5.c: New test.
>
> Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
> ---
>  gcc/config/i386/i386.md                    |  3 ++-
>  gcc/testsuite/gcc.target/i386/pr120427-5.c | 10 ++++++++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr120427-5.c
>
> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
> index eb526997584..a50475bdaf4 100644
> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -2968,7 +2968,8 @@ (define_peephole2
>         (match_operand:SWI248 1 "const_int_operand"))]
>    "optimize_insn_for_size_p () && optimize_size > 1
>     && operands[1] != const0_rtx
> -   && operands[1] != constm1_rtx
> +   && (operands[1] != constm1_rtx
> +       || (<MODE>mode == DImode && LEGACY_INT_REG_P (operands[0])))
>     && IN_RANGE (INTVAL (operands[1]), -128, 127)
>     && !ix86_red_zone_used
>     && REGNO (operands[0]) != SP_REG"
> diff --git a/gcc/testsuite/gcc.target/i386/pr120427-5.c 
> b/gcc/testsuite/gcc.target/i386/pr120427-5.c
> new file mode 100644
> index 00000000000..7199aef7924
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr120427-5.c
> @@ -0,0 +1,10 @@
> +/* { dg-do compile { target { ! ia32 } } } */
> +/* { dg-options "-Oz" } */
> +
> +long long
> +func1 (void)
> +{
> +  return -1;
> +}
> +/* { dg-final { scan-assembler-times "pushq\[ \\t\]+\\\$-1" 1 } } */
> +/* { dg-final { scan-assembler-times "popq\[ \\t\]+%rax" 1 } } */
> --
> 2.50.1
>


-- 
BR,
Hongtao

Reply via email to