[llvm-bugs] [Bug 43217] New: [X86][SSE] Access a scalar float/double as a free extract from a broadcast load

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 4 03:47:21 PDT 2019


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

            Bug ID: 43217
           Summary: [X86][SSE] Access a scalar float/double as a free
                    extract from a broadcast load
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: andrea.dibiagio at gmail.com, craig.topper at gmail.com,
                    llvm-bugs at lists.llvm.org, llvm-dev at redking.me.uk,
                    spatel+llvm at rotateright.com

Current Codegen: https://godbolt.org/z/nm4NKg

#include <x86intrin.h>

__m256 broadcast_scl(float *src, float *dst) {
    float f = *src;
    *dst = f;
    return _mm256_set1_ps(f);
}

__m256 broadcast_vec(float *src, float *dst) {
    __m256 v = _mm256_set1_ps(*src);
    *dst = _mm256_cvtss_f32(v);
    return v;
}

Both these result in a scalar load, scalar store and a broadcast (on AVX1 split
across 2 instruction):

  vmovss (%rdi), %xmm1 # xmm1 = mem[0],zero,zero,zero
  vpermilps $0, %xmm1, %xmm0 # xmm0 = xmm1[0,0,0,0]
  vmovss %xmm1, (%rsi)
  vinsertf128 $1, %xmm0, %ymm0, %ymm0
  retq

But we could do this more efficiently as:

  vbroadcastss (%rdi), %ymm0
  vmovss %xmm0, (%rsi)
  retq

We could probably achieve this in DAG by just replacing other uses of the
loaded scalar as a (free) extract of the broadcast.

-- 
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/20190904/a539f755/attachment.html>


More information about the llvm-bugs mailing list