[llvm-bugs] [Bug 39474] New: Failure to simplify abs(select(-x, +x, cond)) -> abs(x)
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Oct 29 06:39:49 PDT 2018
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: unassignedbugs at nondot.org
Reporter: llvm-dev at redking.me.uk
CC: filcab at gmail.com, llvm-bugs at lists.llvm.org,
spatel+llvm at rotateright.com, tilkax at gmail.com
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181029/5f61c51b/attachment.html>
More information about the llvm-bugs
mailing list