[llvm-bugs] [Bug 30585] New: passing a compile-time constant value to a struct { float f[4]; } arg uses two 16B loads instead of two 8B zero-extending loads, wasting space on constants

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Oct 1 07:56:09 PDT 2016


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

            Bug ID: 30585
           Summary: passing a compile-time constant value to a struct {
                    float f[4]; } arg uses two 16B loads instead of two 8B
                    zero-extending loads, wasting space on constants
           Product: new-bugs
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: peter at cordes.ca
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Clang wastes space on zero padding that could be generated for free by a
narrower load (like gcc uses).

// clang3.9 -O3:  https://godbolt.org/g/9L5HnG
struct foo { float f[4];  };

void ext(struct foo A);
void pass_args() {
  struct foo A = { {1, 2, 3, 4} };
  ext(A);
}

  movaps  xmm0, xmmword ptr [rip + .LCPI0_0] # xmm0 = <1,2,u,u>
  movaps  xmm1, xmmword ptr [rip + .LCPI0_1] # xmm1 = <3,4,u,u>
  jmp     ext                     # TAILCALL

.LCPI0_0:
        .long   1065353216              # float 1
        .long   1073741824              # float 2
        .zero   4
        .zero   4
... and another 16B vector.

More efficient would be using MOVSD to load 8 bytes and zero the upper half of
the register.

gcc uses MOVQ (and narrower constants), but if any CPUs care about integer vs.
float domains for loads, MOVSD is better.  It definitely has no downsides vs.
MOVQ for this purpose: same number of instruction bytes and the same zeroing of
the upper 8 bytes (when the source is a memory operand).

MOVAPS is actually one byte shorter, but that's probably less important than
keeping the constants compact.

Sorry for the long title, maybe it's too specific.

-- 
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/20161001/5150d944/attachment.html>


More information about the llvm-bugs mailing list