[llvm-bugs] [Bug 33301] New: [X86][SSE] Failure to keep horizontal min/max reductions on vector unit

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jun 4 06:45:05 PDT 2017


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

            Bug ID: 33301
           Summary: [X86][SSE] Failure to keep horizontal min/max
                    reductions on vector unit
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: llvm-bugs at lists.llvm.org, spatel+llvm at rotateright.com
            Blocks: 32841

This is preventing us detecting min/max reductions for [Bug #32841] 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


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=32841
[Bug 32841] [X86][SSE] Use PHMINPOSUW for i8/i16 min/max reductions
-- 
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/20170604/f226e48d/attachment.html>


More information about the llvm-bugs mailing list