https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125893
Bug ID: 125893
Summary: TARGET_LCP_STALL peephole uses extra registers
Product: gcc
Version: 16.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
CC: liuhongt at gcc dot gnu.org
Target Milestone: ---
Target: x86
;; Don't move an immediate directly to memory when the instruction
;; gets too big, or if LCP stalls are a problem for 16-bit moves.
(define_peephole2
[(match_scratch:SWI124 1 "<r>")
(set (match_operand:SWI124 0 "memory_operand")
(const_int 0))]
"optimize_insn_for_speed_p ()
&& ((<MODE>mode == HImode
&& TARGET_LCP_STALL)
|| (!TARGET_USE_MOV0
&& TARGET_SPLIT_LONG_MOVES
&& get_attr_length (insn) >= ix86_cur_cost ()->large_insn))
&& peep2_regno_dead_p (0, FLAGS_REG)"
[(parallel [(set (match_dup 2) (const_int 0))
(clobber (reg:CC FLAGS_REG))])
(set (match_dup 0) (match_dup 1))]
"operands[2] = gen_lowpart (SImode, operands[1]);")
uses extra registers:
[hjl@gnu-tgl-3 pr125856]$ cat s.c
/* { dg-do compile } */
/* { dg-options "-O2 -march=x86-64" } */
/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc'). */
/* { dg-final { check-function-bodies "**" "" "" { target lp64 } {^\t?\.} } }
*/
/*
**foo:
**...
*/
void
foo (short *dst)
{
dst[0] = 3;
asm volatile ("" : : : "memory");
dst[1] = 3;
}
[hjl@gnu-tgl-3 pr125856]$ gcc -S -O2 s.c
[hjl@gnu-tgl-3 pr125856]$ cat s.s
.file "s.c"
.text
.p2align 4
.globl foo
.type foo, @function
foo:
.LFB0:
.cfi_startproc
movl $3, %eax
movw %ax, (%rdi)
movl $3, %edx
movw %dx, 2(%rdi)
ret
.cfi_endproc
.LFE0:
.size foo, .-foo
.ident "GCC: (GNU) 16.1.1 20260515 (Red Hat 16.1.1-2)"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 pr125856]$