<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - using memory operand form of insert and extract instructions would eliminate loads and stores"
href="http://llvm.org/bugs/show_bug.cgi?id=17268">17268</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>using memory operand form of insert and extract instructions would eliminate loads and stores
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kkhoo@perfwizard.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>