https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122324
Bug ID: 122324
Summary: C compiler doesn't optimize abs
Product: gcc
Version: 13.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
[hjl@gnu-tgl-3 pr99930]$ cat z.c
#include <stdlib.h>
float t(float x)
{
return -abs (x);
}
[hjl@gnu-tgl-3 pr99930]$ /usr/gcc-13.2.1-x32/bin/gcc -O3 -S z.c
[hjl@gnu-tgl-3 pr99930]$ cat z.s
.file "z.c"
.text
.p2align 4
.globl t
.type t, @function
t:
.LFB11:
.cfi_startproc
cvttss2sil %xmm0, %edx
pxor %xmm0, %xmm0
movl %edx, %eax
negl %eax
cmovns %edx, %eax
cvtsi2ssl %eax, %xmm0
ret
.cfi_endproc
.LFE11:
.size t, .-t
.ident "GCC: (GNU) 13.2.1 20240112"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 pr99930]$ /usr/gcc-13.2.1-x32/bin/g++ -O3 -S z.c
[hjl@gnu-tgl-3 pr99930]$ cat z.s
.file "z.c"
.text
.p2align 4
.globl _Z1tf
.type _Z1tf, @function
_Z1tf:
.LFB22:
.cfi_startproc
orps .LC1(%rip), %xmm0
ret
.cfi_endproc
.LFE22:
.size _Z1tf, .-_Z1tf
.section .rodata.cst16,"aM",@progbits,16
.align 16
.LC1:
.long -2147483648
.long 0
.long 0
.long 0
.ident "GCC: (GNU) 13.2.1 20240112"
.section .note.GNU-stack,"",@progbits
[hjl@gnu-tgl-3 pr99930]$