[llvm-bugs] [Bug 39920] New: [X86] Failure to use PHADDD on Intel CPUs on the second to last step of a v8i32 pairwise reduction

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 7 15:25:05 PST 2018


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

            Bug ID: 39920
           Summary: [X86] Failure to use PHADDD on Intel CPUs on the
                    second to last step of a v8i32 pairwise reduction
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: craig.topper at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

I think we should use HADDPS for the first reduction step of this on Intel CPUs

define fastcc i32 @pairwise_reduction4i32(<4 x i32> %rdx, i32 %f1) {
  %rdx.shuf.1.0 = shufflevector <4 x i32> %rdx, <4 x i32> undef,<4 x i32> <i32
0, i32 2, i32 undef, i32 undef>
  %rdx.shuf.1.1 = shufflevector <4 x i32> %rdx, <4 x i32> undef,<4 x i32> <i32
1, i32 3, i32 undef, i32 undef>
  %bin.rdx8 = add <4 x i32> %rdx.shuf.1.0, %rdx.shuf.1.1
  %rdx.shuf.2.0 = shufflevector <4 x i32> %bin.rdx8, <4 x i32> undef,<4 x i32>
<i32 0, i32 undef, i32 undef, i32 undef>
  %rdx.shuf.2.1 = shufflevector <4 x i32> %bin.rdx8, <4 x i32> undef,<4 x i32>
<i32 1, i32 undef, i32 undef, i32 undef>
  %bin.rdx9 = add <4 x i32> %rdx.shuf.2.0, %rdx.shuf.2.1

  %r = extractelement <4 x i32> %bin.rdx9, i32 0
  ret i32 %r
}

This is the assembly we get on sse4.1

        pshufd  $232, %xmm0, %xmm1      # xmm1 = xmm0[0,2,2,3]
        pshufd  $237, %xmm0, %xmm0      # xmm0 = xmm0[1,3,2,3]
        paddd   %xmm1, %xmm0
        pshufd  $229, %xmm0, %xmm1      # xmm1 = xmm0[1,1,2,3]
        paddd   %xmm0, %xmm1
        movd    %xmm1, %eax
        retq


PHADDD uses 2 shuffles internally on Intel CPus, but as you can see the
assembly we emitted also uses 2 shuffles. So I don't think we saved anything by
avoiding PHADDD.

-- 
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/20181207/40842b9b/attachment-0001.html>


More information about the llvm-bugs mailing list