https://bugs.llvm.org/show_bug.cgi?id=39474
Bug ID: 39474
Summary: Failure to simplify abs(select(-x,+x,cond)) -> abs(x)
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
https://godbolt.org/z/IiYvRv
#include <algorithm>
int abs_s32(bool b, int x)
{
return std::abs(b ? -x : x);
}
float abs_f32(bool b, float x)
{
return std::abs(b ? -x : x);
}
_Z7abs_s32bi: # @_Z7abs_s32bi
movl %esi, %ecx
negl %ecx
testl %edi, %edi
cmovel %esi, %ecx
movl %ecx, %eax
negl %eax
cmovll %ecx, %eax
retq
_Z7abs_f32bf: # @_Z7abs_f32bf
testl %edi, %edi
je .LBB1_2
xorps .LCPI1_0(%rip), %xmm0
.LBB1_2:
andps .LCPI1_1(%rip), %xmm0
retq
gcc manages to optimize both:
_Z7abs_s32bi:
movl %esi, %eax
cltd
xorl %edx, %eax
subl %edx, %eax
ret
_Z7abs_f32bf:
andps .LC0(%rip), %xmm0
ret
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs