[llvm-bugs] [Bug 31286] New: Instcombine(?) should factor broadcasts across math

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 5 17:31:05 PST 2016


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

            Bug ID: 31286
           Summary: Instcombine(?) should factor broadcasts across math
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: mkuper at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Not actually sure "factor" is the right term here, what I mean is that we're
missing:

bcast(x) + bcast(y) -> bcast(x + y)

Right now, for:

#include <immintrin.h>

__m128 bar(float f, float g, float h, float i) {
  __m128 v0 = _mm_set_ps1(f);
  __m128 v1 = _mm_set_ps1(g);
  __m128 v2 = _mm_set_ps1(h);
  __m128 v3 = _mm_set_ps1(i);
  return v0 + v1 + v2 + v3;
}

We get:

bar(float, float, float, float):                             # @bar(float,
float, float, float)
        shufps  $0, %xmm0, %xmm0        # xmm0 = xmm0[0,0,0,0]
        shufps  $0, %xmm1, %xmm1        # xmm1 = xmm1[0,0,0,0]
        shufps  $0, %xmm2, %xmm2        # xmm2 = xmm2[0,0,0,0]
        shufps  $0, %xmm3, %xmm3        # xmm3 = xmm3[0,0,0,0]
        addps   %xmm1, %xmm0
        addps   %xmm2, %xmm0
        addps   %xmm3, %xmm0
        retq
Instead of:

bar(float, float, float, float):
        addss   %xmm1, %xmm0
        addss   %xmm2, %xmm0
        addss   %xmm3, %xmm0
        shufps  $0, %xmm0, %xmm0
        ret

There's another odd thing here - in IR we represent each broadcast as a
sequence of insertelements, instead of an insert + shuffle, which, I believe,
is the canonical form (at least, this is what the vectorizer produces)
That should probably be fixed first, so we have only one canonical broadcast to
match.

-- 
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/20161206/b0c6170c/attachment-0001.html>


More information about the llvm-bugs mailing list