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