[LLVMbugs] [Bug 9019] New: __builtin_fabs shouldn't lower to libm call
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Jan 21 11:26:20 PST 2011
http://llvm.org/bugs/show_bug.cgi?id=9019
Summary: __builtin_fabs shouldn't lower to libm call
Product: new-bugs
Version: trunk
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: nlewycky at google.com
CC: llvmbugs at cs.uiuc.edu
This program:
float f(float x) {
return __builtin_fabsf(x);
}
requires -lm when built by clang -O0 but not when built by gcc or clang -O2.
GCC emits this code at -O2 levels (-O0 has no call either):
f:
.LFB0:
.cfi_startproc
movss .LC0(%rip), %xmm1
andps %xmm1, %xmm0
ret
.cfi_endproc
[...]
.LC0:
.long 2147483647
.long 0
.long 0
.long 0
without -fno-errno or -ffast-math or any other such flags. Clang -O2 will emit
this IR:
define float @f(float %x) nounwind readnone {
entry:
%call = tail call float @fabsf(float %x)
ret float %call
}
but in llc -O0 we emit the call as written and in llc -O2 we replace it with an
andps like gcc.
Either llc -O0 should learn to lower fabs/fabsf calls to 'and', or clang should
lower __builtin_fabs differently. I think I prefer the latter, but the backend
would need to be improved first. The lowering in LLVM IR would be:
define float @f(float %x) {
%cast = bitcast float %x to i32
%abs.i = and i32 %cast, 2147483647
%abs = bitcast i32 %abs.i to float
ret float %abs
}
which produces this sub-optimal code through llc -O2:
movd %xmm0, %eax
andl $2147483647, %eax # imm = 0x7FFFFFFF
movd %eax, %xmm0
ret
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list