[LLVMbugs] [Bug 21990] New: generate a vector load for a non-zero vector store of constants?

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Dec 19 13:59:05 PST 2014


            Bug ID: 21990
           Summary: generate a vector load for a non-zero vector store of
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Spinning this off from bug 21711, comment 6:

$ cat store_non_zero_constants.ll
define void @merge_const_store_vec(i32* %p) {
  %p0 = getelementptr inbounds i32* %p, i64 0
  %p1 = getelementptr inbounds i32* %p, i64 1
  %p2 = getelementptr inbounds i32* %p, i64 2
  %p3 = getelementptr inbounds i32* %p, i64 3
  %p4 = getelementptr inbounds i32* %p, i64 4
  %p5 = getelementptr inbounds i32* %p, i64 5
  %p6 = getelementptr inbounds i32* %p, i64 6
  %p7 = getelementptr inbounds i32* %p, i64 7
  store i32 0, i32* %p0, align 4
  store i32 1, i32* %p1, align 4
  store i32 2, i32* %p2, align 4
  store i32 3, i32* %p3, align 4
  store i32 4, i32* %p4, align 4
  store i32 5, i32* %p5, align 4
  store i32 6, i32* %p6, align 4
  store i32 7, i32* %p7, align 4
  ret void

Currently (r224581), we do not attempt to merge stores of non-zero constants
beyond the largest scalar store size. Presumably, this is to avoid generating a
vector load of those constants rather than materializing them in registers as

So for an x86 AVX machine we generate:
0000    movabsq    $0x100000000, %rax      ## imm = 0x100000000
000a    movq    %rax, (%rdi)
000d    movabsq    $0x300000002, %rax      ## imm = 0x300000002
0017    movq    %rax, 0x8(%rdi)
001b    movabsq    $0x500000004, %rax      ## imm = 0x500000004
0025    movq    %rax, 0x10(%rdi)
0029    movabsq    $0x700000006, %rax      ## imm = 0x700000006
0033    movq    %rax, 0x18(%rdi)
0037    retq

That's 55 bytes of instructions before the 'ret'. If we merged all those
constants and loaded them from memory instead, we'd have something like this:

0000    vmovdqu    LCP_0(rip), %ymm0
0005    vmovdqu    %ymm0, (%rdi)
000a    retq

1. Add 32 bytes of constant pool data memory.
2. Subtract ~45 bytes of instruction memory.
3. Add a load instruction.
4. Remove 3 store instructions and 4 load immediates.

Is it worth generating a load to have a net savings in memory usage?

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/20141219/dc098b9a/attachment.html>

More information about the llvm-bugs mailing list