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

* [Bug rtl-optimization/110240] Unnecessary register move in indexed swap routine
  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 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-13 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-06-13
             Status|UNCONFIRMED                 |NEW
          Component|target                      |rtl-optimization
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed (though it is not exactly a target specific issue).

REE transforms:
(insn 7 4 8 2 (set (reg:SI 0 ax [orig:82 _1 ] [82])
        (mem:SI (reg/v/f:DI 4 si [orig:93 b ] [93]) [1 *b_13(D)+0 S4 A32]))
"/app/example.cpp":3:10 91 {*movsi_internal}
     (nil))
(insn 8 7 9 2 (set (reg:SI 1 dx [orig:87 _6 ] [87])
        (mem:SI (plus:DI (reg/v/f:DI 4 si [orig:93 b ] [93])
                (const_int 4 [0x4])) [1 MEM[(unsigned int *)b_13(D) + 4B]+0 S4
A32])) "/app/example.cpp":3:20 91 {*movsi_internal}
     (nil))
(insn 9 8 10 2 (set (reg:DI 2 cx [orig:94 _1 ] [94])
        (zero_extend:DI (reg:SI 0 ax [orig:82 _1 ] [82])))
"/app/example.cpp":3:10 159 {*zero_extendsidi2}
     (nil))
(insn 10 9 11 2 (set (reg:DI 36 r8 [orig:95 _6 ] [95])
        (zero_extend:DI (reg:SI 1 dx [orig:87 _6 ] [87])))
"/app/example.cpp":3:20 159 {*zero_extendsidi2}
     (nil))

Into:
(insn 7 4 28 2 (set (reg:DI 2 cx)
        (zero_extend:DI (mem:SI (reg/v/f:DI 4 si [orig:93 b ] [93]) [1
*b_13(D)+0 S4 A32]))) "/app/example.cpp":3:10 159 {*zero_extendsidi2}
     (nil))
(insn 28 7 8 2 (set (reg:DI 0 ax)
        (reg:DI 2 cx)) "/app/example.cpp":3:10 -1
     (nil))
(insn 8 28 29 2 (set (reg:DI 36 r8)
        (zero_extend:DI (mem:SI (plus:DI (reg/v/f:DI 4 si [orig:93 b ] [93])
                    (const_int 4 [0x4])) [1 MEM[(unsigned int *)b_13(D) + 4B]+0
S4 A32]))) "/app/example.cpp":3:20 159 {*zero_extendsidi2}
     (nil))
(insn 29 8 11 2 (set (reg:DI 1 dx)
        (reg:DI 36 r8)) "/app/example.cpp":3:20 -1
     (nil))

Which is good.

cprop_hardreg can copyprop the value of r8 into dx's usage and able to remove
insn29. But does not do the same for cx for ax, I didn't look into why.
This is why the only one mov and not 2.

^ 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).