<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - 30% performance deficiency vs GCC because of excessive vectorization on -march=slm"
   href="https://llvm.org/bugs/show_bug.cgi?id=25108">25108</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>30% performance deficiency vs GCC because of excessive vectorization on -march=slm
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>egor.kochetov@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=15033" name="attach_15033" title="c++ reproducer, Makefile, two disassembled functions.">attachment 15033</a> <a href="attachment.cgi?id=15033&action=edit" title="c++ reproducer, Makefile, two disassembled functions.">[details]</a></span>
c++ reproducer, Makefile, two disassembled functions.

Here is the C++ source that gets vectorized by clang and is not vectorized by
gcc, it is the function 'compute' of the attached cpp file.

template <typename T>
void compute (T* v) {
    for (int i = 0; i < 10000; ++i) {        
        // fw pass
        for (int i = 0; i < 6; ++i) {
            v [i] += v [i + 1];
            v [i] *= v [i + 2];
        }
        //back pass
        for (int i = 7; i > 1; --i) {
            v [i] += v [i - 1];
            v [i] *= v [i - 2];
        }
    }
}
The vectorized version happens to work slower, when compiled both for float and
for double numbers, on a Silvermont Intel machine. The test run timings are as
follows:

clang:
float time: 0.000043 ms
double time: 0.000059 ms

gcc:
float time: 0.000029 ms
double time: 0.000043 ms
The source was compiled with -Ofast -m64 -g -march=slm -mfpmath=sse -fPIE. 32
bit build shows the same result.

This difference reproduces a real one which is measured in seconds in one of
the programs I deal with.
It seems, that vectorization costs in clang are not set up correctly for
-march=slm. When compiling by clang with -fno-slp-vectorize, the resulting
performance matches gcc.

Compilers under consideration are: gcc 6.0 trunk vs clang 3.8 trunk.

The attachment is the archive with the C++ reproducer source, Makefile and
assemblies for float version got from the two compilers.

To run the reproducer using the Makefile attached, call `make clean run; make
clean run COMPILER=gcc` after fixing compiler paths in the Makefile.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>