[llvm-bugs] [Bug 38333] New: C++ "f < 0 ? -f : f" generates much worse code than fabs

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 27 00:31:31 PDT 2018


            Bug ID: 38333
           Summary: C++ "f < 0 ? -f : f" generates much worse code than
           Product: new-bugs
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: bratell at opera.com
                CC: llvm-bugs at lists.llvm.org

Example at:

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180727/57b1ba1d/attachment.html>

More information about the llvm-bugs mailing list