public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/110240] New: Unnecessary register move in indexed swap routine
@ 2023-06-13 18:59 tkoenig at gcc dot gnu.org
  2023-06-13 19:16 ` [Bug rtl-optimization/110240] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2023-06-13 18:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110240

            Bug ID: 110240
           Summary: Unnecessary register move in indexed swap routine
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkoenig at gcc dot gnu.org
  Target Milestone: ---

void swap (unsigned int * restrict a, unsigned int * restrict b)
{
  if (a[b[0]] > a[b[1]])
    {
      unsigned int tmp = b[0];
      b[0] = b[1];
      b[1] = tmp;
    }
}
$ gcc -O3 -S swap.c

gets me

swap:
.LFB0:
        .cfi_startproc
        movl    (%rsi), %ecx
        movl    4(%rsi), %r8d
        movq    %rcx, %rax
        movl    (%rdi,%rcx,4), %ecx
        cmpl    %ecx, (%rdi,%r8,4)
        jnb     .L1
        movl    %r8d, (%rsi)
        movl    %eax, 4(%rsi)
.L1:
        ret
        .cfi_endproc

where the

        movq    %rcx, %rax

is unneeded, because rcs is not overwritten.

(It is probably also a zero-latency operation due to register renaming,
but still).

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-13 19:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13 18:59 [Bug target/110240] New: Unnecessary register move in indexed swap routine tkoenig at gcc dot gnu.org
2023-06-13 19:16 ` [Bug rtl-optimization/110240] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).