<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 - [X86][SSE] Failure to keep horizontal min/max reductions on vector unit"
   href="https://bugs.llvm.org/show_bug.cgi?id=33301">33301</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[X86][SSE] Failure to keep horizontal min/max reductions on vector unit
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>32841
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is preventing us detecting min/max reductions for [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [X86][SSE] Use PHMINPOSUW for i8/i16 min/max reductions"
   href="show_bug.cgi?id=32841">Bug #32841</a>] etc.

#include <x86intrin.h>
int max_4s32(__v4si v) {
  v = _mm_max_epi32(v, __builtin_shufflevector(v,v,2,3,-1,-1));
  v = _mm_max_epi32(v, __builtin_shufflevector(v,v,1,-1,-1,-1));
  return v[0];
}
unsigned short min_8u16(__v8hu v) {
  v = _mm_min_epu16(v, __builtin_shufflevector(v,v,4,5,6,7,-1,-1,-1,-1));
  v = _mm_min_epu16(v, __builtin_shufflevector(v,v,2,3,-1,-1,-1,-1,-1,-1));
  v = _mm_min_epu16(v, __builtin_shufflevector(v,v,1,-1,-1,-1,-1,-1,-1,-1));
  return v[0];
}

clang -O3 -march=btver2 -emit-llvm

define i32 @max_4s32(<4 x i32>) {
  %2 = shufflevector <4 x i32> %0, <4 x i32> undef, <4 x i32> <i32 2, i32 3,
i32 undef, i32 undef>
  %3 = icmp slt <4 x i32> %2, %0
  %4 = select <4 x i1> %3, <4 x i32> %0, <4 x i32> %2
  %5 = shufflevector <4 x i32> %4, <4 x i32> undef, <4 x i32> <i32 1, i32
undef, i32 undef, i32 undef>
  %6 = icmp sgt <4 x i32> %4, %5
  %7 = extractelement <4 x i1> %6, i32 0
  %8 = extractelement <4 x i32> %4, i32 0
  %9 = extractelement <4 x i32> %4, i32 1
  %10 = select i1 %7, i32 %8, i32 %9
  ret i32 %10
}

define zeroext i16 @min_8u16(<8 x i16>) {
  %2 = shufflevector <8 x i16> %0, <8 x i16> undef, <8 x i32> <i32 4, i32 5,
i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
  %3 = icmp ugt <8 x i16> %2, %0
  %4 = select <8 x i1> %3, <8 x i16> %0, <8 x i16> %2
  %5 = shufflevector <8 x i16> %4, <8 x i16> undef, <8 x i32> <i32 2, i32 3,
i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
  %6 = icmp ult <8 x i16> %4, %5
  %7 = select <8 x i1> %6, <8 x i16> %4, <8 x i16> %5
  %8 = shufflevector <8 x i16> %7, <8 x i16> undef, <8 x i32> <i32 1, i32
undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
  %9 = icmp ult <8 x i16> %7, %8
  %10 = extractelement <8 x i1> %9, i32 0
  %11 = extractelement <8 x i16> %7, i32 0
  %12 = extractelement <8 x i16> %7, i32 1
  %13 = select i1 %10, i16 %11, i16 %12
  ret i16 %13
}

max_4s32:
        vpshufd $78, %xmm0, %xmm1       # xmm1 = xmm0[2,3,0,1]
        vpmaxsd %xmm0, %xmm1, %xmm0
        vpshufd $229, %xmm0, %xmm1      # xmm1 = xmm0[1,1,2,3]
        vmovd   %xmm0, %edx
        vpextrd $1, %xmm0, %eax
        vpcmpgtd        %xmm1, %xmm0, %xmm1
        vpextrb $0, %xmm1, %ecx
        testb   $1, %cl
        cmovnel %edx, %eax
        retq

min_8u16:
        vpshufd $78, %xmm0, %xmm1       # xmm1 = xmm0[2,3,0,1]
        vmovdqa .LCPI1_0(%rip), %xmm2   # xmm2 =
[32768,32768,32768,32768,32768,32768,32768,32768]
        vpminuw %xmm0, %xmm1, %xmm0
        vpshufd $229, %xmm0, %xmm1      # xmm1 = xmm0[1,1,2,3]
        vpminuw %xmm1, %xmm0, %xmm0
        vpsrld  $16, %xmm0, %xmm1
        vmovd   %xmm0, %edx
        vpextrw $1, %xmm0, %eax
        vpxor   %xmm2, %xmm0, %xmm3
        vpxor   %xmm2, %xmm1, %xmm1
        vpcmpgtw        %xmm3, %xmm1, %xmm1
        vpextrb $0, %xmm1, %ecx
        testb   $1, %cl
        cmovnew %dx, %ax
        retq</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [X86][SSE] Use PHMINPOSUW for i8/i16 min/max reductions"
   href="https://bugs.llvm.org/show_bug.cgi?id=32841">Bug 32841</a>] [X86][SSE] Use PHMINPOSUW for i8/i16 min/max reductions
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>