<html>
    <head>
      <base href="http://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 --- - constant vector value splatted at runtime with broadcast instruction instead of loaded (only core-avx2 target?)"
   href="http://llvm.org/bugs/show_bug.cgi?id=20054">20054</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>constant vector value splatted at runtime with broadcast instruction instead of loaded (only core-avx2 target?)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ ./clang -v
clang version 3.5.0 (210980)
Target: x86_64-apple-darwin13.2.0
Thread model: posix

$ cat splat.c 
#include <xmmintrin.h>

__m128 splat(__m128 x) {
    return _mm_add_ps(x, _mm_set1_ps(1.0f));
}

---------------------------------------------------------

That "1.0f" constant vector is being loaded as a scalar value and then splatted
across the xmm register for the core-avx2 target:


$ ./clang -O1 -fomit-frame-pointer splat.c -march=core-avx2 -S -o -
    .section    __TEXT,__text,regular,pure_instructions
    .macosx_version_min 10, 9
    .section    __TEXT,__literal4,4byte_literals
    .align    2
LCPI0_0:
    .long    1065353216              ## float 1
    .section    __TEXT,__text,regular,pure_instructions
    .globl    _splat
    .align    4, 0x90
_splat:                                 ## @splat
    .cfi_startproc
## BB#0:                                ## %entry
    vbroadcastss    LCPI0_0(%rip), %xmm1
    vaddps    %xmm1, %xmm0, %xmm0
    retq
    .cfi_endproc


.subsections_via_symbols

--------------------------------------------------------

But with any (?) other x86 targets, we make the size-speed tradeoff and just
load a full 128-bit vector:


$ ./clang -O1 -fomit-frame-pointer splat.c -march=corei7-avx -S -o -
    .section    __TEXT,__text,regular,pure_instructions
    .macosx_version_min 10, 9
    .section    __TEXT,__literal16,16byte_literals
    .align    4
LCPI0_0:
    .long    1065353216              ## float 1.000000e+00
    .long    1065353216              ## float 1.000000e+00
    .long    1065353216              ## float 1.000000e+00
    .long    1065353216              ## float 1.000000e+00
    .section    __TEXT,__text,regular,pure_instructions
    .globl    _splat
    .align    4, 0x90
_splat:                                 ## @splat
    .cfi_startproc
## BB#0:                                ## %entry
    vaddps    LCPI0_0(%rip), %xmm0, %xmm0
    retq
    .cfi_endproc</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>