[LLVMbugs] [Bug 17268] New: using memory operand form of insert and extract instructions would eliminate loads and stores

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Sep 17 11:13:14 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=17268

            Bug ID: 17268
           Summary: using memory operand form of insert and extract
                    instructions would eliminate loads and stores
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: kkhoo at perfwizard.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following codegen is following the Intel/AMD optimization guidelines and
splitting unaligned 32-byte loads and stores into 16-byte operations by using
'vinsertf128' and 'vextractf128', but it could have eliminated 4 'vmovups'
instructions by choosing the memory operand forms of the insert/extract
instructions rather than the register operand forms.

Eliminating the extra instructions would save 16 instruction bytes. 74 bytes
reduced to 58 bytes = 22% smaller code with theoretically identical performance
for targets such as Intel Sandy Bridge and AMD Bulldozer/Piledriver.

Note: the same problem appears in the case where the loop-end condition is a
variable, but I made the example case use a constant loop-end to simplify the
codegen.

$ ./clang -v
clang version 3.4 (trunk 189776)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

$ cat mulps.c
void foo(float *x) {
    int i;
    for (i=0; i<16; i++) {
        x[i] = x[i] * x[i];
    }
}

$ ./clang -S -O3 -fomit-frame-pointer -march=corei7-avx  -o /dev/stdout mulps.c 
    .section    __TEXT,__text,regular,pure_instructions
    .globl    _foo
    .align    4, 0x90
_foo:                                   ## @foo
    .cfi_startproc
## BB#0:                                ## %for.end
    vmovups    (%rdi), %xmm0
    vmovups    16(%rdi), %xmm1
    vinsertf128    $1, %xmm1, %ymm0, %ymm0
    vmulps    %ymm0, %ymm0, %ymm0
    vextractf128    $1, %ymm0, %xmm1
    vmovups    %xmm1, 16(%rdi)
    vmovups    %xmm0, (%rdi)
    vmovups    32(%rdi), %xmm0
    vmovups    48(%rdi), %xmm1
    vinsertf128    $1, %xmm1, %ymm0, %ymm0
    vmulps    %ymm0, %ymm0, %ymm0
    vextractf128    $1, %ymm0, %xmm1
    vmovups    %xmm1, 48(%rdi)
    vmovups    %xmm0, 32(%rdi)
    vzeroupper
    ret

-- 
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/20130917/ba94b8ad/attachment.html>


More information about the llvm-bugs mailing list