<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - extractelement on <8 x i2> uses xmm which is unnecessary complicated"
   href="https://bugs.llvm.org/show_bug.cgi?id=44917">44917</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>extractelement on <8 x i2> uses xmm which is unnecessary complicated
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>9.0
          </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>enhancement
          </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>llvm@henning-thielemann.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Extracting an element from a vector from memory with small integers generates
pretty complicated code.
Problem is that you cannot access vector elements directly from memory with
getelementptr.
Here is an example and how one would certainly implement it in an efficient
way:

$ cat extract8i2.ll
define i16 @extract_vector(i16*, i16) {
_L1:
  %2 = load i16, i16* %0
  %3 = bitcast i16 %2 to <8 x i2>
  %4 = extractelement <8 x i2> %3, i16 %1
  %5 = zext i2 %4 to i16
  ret i16 %5
}

define i16 @extract_bitmanip(i16*, i16) {
_L1:
  %2 = load i16, i16* %0
  %shift = mul i16 2, %1
  %shifted = lshr i16 %2, %shift
  %masked = and i16 3, %shifted
  ret i16 %masked
}

$ llc-9 -mcpu=sandybridge </tmp/extract8i2.ll
        .text
        .file   "<stdin>"
        .globl  extract_vector          # -- Begin function extract_vector
        .p2align        4, 0x90
        .type   extract_vector,@function
extract_vector:                         # @extract_vector
        .cfi_startproc
# %bb.0:                                # %_L1
        movzwl  (%rdi), %eax
        movl    %eax, %ecx
        shrl    $2, %ecx
        andl    $3, %ecx
        movl    %eax, %edx
        andl    $3, %edx
        vmovd   %edx, %xmm0
        vpinsrw $1, %ecx, %xmm0, %xmm0
        movl    %eax, %ecx
        shrl    $4, %ecx
        andl    $3, %ecx
        vpinsrw $2, %ecx, %xmm0, %xmm0
        movl    %eax, %ecx
        shrl    $6, %ecx
        andl    $3, %ecx
        vpinsrw $3, %ecx, %xmm0, %xmm0
        movl    %eax, %ecx
        shrl    $8, %ecx
        andl    $3, %ecx
        vpinsrw $4, %ecx, %xmm0, %xmm0
        movl    %eax, %ecx
        shrl    $10, %ecx
        andl    $3, %ecx
        vpinsrw $5, %ecx, %xmm0, %xmm0
        movl    %eax, %ecx
        shrl    $12, %ecx
        andl    $3, %ecx
        vpinsrw $6, %ecx, %xmm0, %xmm0
        shrl    $14, %eax
        vpinsrw $7, %eax, %xmm0, %xmm0
                                        # kill: def $esi killed $esi def $rsi
        vmovdqa %xmm0, -24(%rsp)
        andl    $7, %esi
        movzwl  -24(%rsp,%rsi,2), %eax
        retq
.Lfunc_end0:
        .size   extract_vector, .Lfunc_end0-extract_vector
        .cfi_endproc
                                        # -- End function
        .globl  extract_bitmanip        # -- Begin function extract_bitmanip
        .p2align        4, 0x90
        .type   extract_bitmanip,@function
extract_bitmanip:                       # @extract_bitmanip
        .cfi_startproc
# %bb.0:                                # %_L1
                                        # kill: def $esi killed $esi def $rsi
        movzwl  (%rdi), %eax
        leal    (%rsi,%rsi), %ecx
                                        # kill: def $cl killed $cl killed $ecx
        shrl    %cl, %eax
        andl    $3, %eax
                                        # kill: def $ax killed $ax killed $eax
        retq
.Lfunc_end1:
        .size   extract_bitmanip, .Lfunc_end1-extract_bitmanip
        .cfi_endproc
                                        # -- End function

        .section        ".note.GNU-stack","",@progbits</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>