https://bugs.llvm.org/show_bug.cgi?id=38333
Bug ID: 38333
Summary: C++ "f < 0 ? -f : f" generates much worse code than
fabs
Product: new-bugs
Version: 6.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Example at:
https://godbolt.org/g/tcNgGG
While optimizing code in the Chromium project, we noticed that fabs generates
much better machine code than "f < 0 ? -f : f". There might be some subtleties
around it, but I'd expect them to generate code that is very similar.
fabs and manually clearing the sign bit are both just an "and" instruction.
"f < 0 ? -f : f" results in 10 machine code instructions, including 2 "and" but
also 4 "move", 1 "cmp", 2 "xor" and 1 "or".
The emitted code is identical in -O1, -O2 and -O3. This was tested in clang
6.0. gcc seems better at this construct, but worse at fabs.
--
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