[llvm-bugs] [Bug 26445] New: [ppc] inefficient code generated for std::max(float, float)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 2 14:53:11 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26445

            Bug ID: 26445
           Summary: [ppc] inefficient code generated for std::max(float,
                    float)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: carrot at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Compile following code with options: $ ~/llvm/obj2/bin/clang++ 
--target=powerpc64le-grtev4-linux-gnu -m64 -mvsx -mcpu=power8 -O2 -c -o t9.o
t9.cc -fno-unroll-loops

#include <algorithm>

float foo(float* input, int s) {
  float max_value = input[0];
  for (int j = 1; j <= s; ++j)
      max_value = std::max(max_value, input[j]);

  return max_value;
}


I got following code for the loop body

.LBB0_2:                                # %for.body
                                        # =>This Inner Loop Header: Depth=1
        lfsu 0, 4(3)
        fcmpu 0, 1, 0
        isel 5, 3, 4, 0
        lwz 5, 0(5)
        mtvsrd 34, 5
        stw 5, -12(1)
        xxsldwi 13, 34, 34, 1
        xscvspdpn 1, 13
        bdnz .LBB0_2


There are several problems in this code snippet

1. instead of compare and choose maximum float value, the generated code uses
isel to choose the address of larger value, then load it into integer register,
then move it to fp register, then expand it to double type.

2. no need to store the max value to memory.


It causes one of our internal applications more than 2x slower.

-- 
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/20160202/b4f446c0/attachment.html>


More information about the llvm-bugs mailing list