https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92807
Sunil Pandey <skpgkp2 at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hjl.tools at gmail dot com, | |skpgkp2 at gmail dot com Summary|gcc generate extra move for |gcc generate extra move for |the snippet code |the snippet code along with | |lea instruction. --- Comment #1 from Sunil Pandey <skpgkp2 at gmail dot com> --- $ cat t1.c #include<stdint.h> uint32_t abs2( uint32_t a ) { uint32_t s = ((a>>15)&0x10001)*0xffff; return (a+s)^s; } $ gcc --version gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc -Ofast -S t1.c -o t1.s.gcc.9 $ cat t1.s.gcc.9 .file "t1.c" .text .p2align 4 .globl abs2 .type abs2, @function abs2: .LFB0: .cfi_startproc movl %edi, %edx shrl $15, %edx andl $65537, %edx movl %edx, %eax sall $16, %eax subl %edx, %eax movl %eax, %edx leal (%rdi,%rax), %eax xorl %edx, %eax ret .cfi_endproc .LFE0: .size abs2, .-abs2 .ident "GCC: (GNU) 9.2.1 20190827 (Red Hat 9.2.1-1)" .section .note.GNU-stack,"",@progbits Intel compiler generate add instead of lea as well as 1 less mov instruction for same code. $ icc -Ofast -S t1.c -o t1.s.icc $ cat t1.s.icc .L_2__routine_start_abs2_0: # -- Begin abs2 .text # mark_begin; .align 16,0x90 .globl abs2 # --- abs2(uint32_t) abs2: # parameter 1: %edi ..B1.1: # Preds ..B1.0 # Execution count [1.00e+00] .cfi_startproc ..___tag_value_abs2.1: ..L2: #3.1 movl %edi, %edx #4.23 shrl $15, %edx #4.23 andl $65537, %edx #4.27 movl %edx, %eax #4.36 shll $16, %eax #4.36 subl %edx, %eax #4.36 addl %eax, %edi #5.19 xorl %edi, %eax #5.22 ret #5.22 .align 16,0x90 # LOE .cfi_endproc # mark_end; .type abs2,@function .size abs2,.-abs2 ..LNabs2.0: .data # -- End abs2 .data .section .note.GNU-stack, "" # End