<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Suboptimal materialization of += 1 as -= -1"
href="https://bugs.llvm.org/show_bug.cgi?id=52032">52032</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Suboptimal materialization of += 1 as -= -1
</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>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>struct b
{
int a[100000];
};
void
plus1(struct b *a)
{
int i;
for (i=0;i<64;i++)
a->a[i]+=1;
}
Trunk -O3 -march=haswell:
plus1(b*): # @plus1(b*)
vpcmpeqd %ymm0, %ymm0, %ymm0
vmovdqu (%rdi), %ymm1
vmovdqu 32(%rdi), %ymm2
vmovdqu 64(%rdi), %ymm3
vmovdqu 96(%rdi), %ymm4
vpsubd %ymm0, %ymm1, %ymm1
vmovdqu %ymm1, (%rdi)
vpsubd %ymm0, %ymm2, %ymm1
vmovdqu %ymm1, 32(%rdi)
vpsubd %ymm0, %ymm3, %ymm1
vmovdqu %ymm1, 64(%rdi)
vpsubd %ymm0, %ymm4, %ymm1
vmovdqu %ymm1, 96(%rdi)
vmovdqu 128(%rdi), %ymm1
vpsubd %ymm0, %ymm1, %ymm1
vmovdqu %ymm1, 128(%rdi)
vmovdqu 160(%rdi), %ymm1
vpsubd %ymm0, %ymm1, %ymm1
vmovdqu %ymm1, 160(%rdi)
vmovdqu 192(%rdi), %ymm1
vpsubd %ymm0, %ymm1, %ymm1
vmovdqu %ymm1, 192(%rdi)
vmovdqu 224(%rdi), %ymm1
vpsubd %ymm0, %ymm1, %ymm0
vmovdqu %ymm0, 224(%rdi)
vzeroupper
retq
ICC/GCC produces:
plus1(b*):
vmovdqu .L_2il0floatpacket.0(%rip), %ymm7 #12.14
vpaddd (%rdi), %ymm7, %ymm0 #12.5
vpaddd 32(%rdi), %ymm7, %ymm1 #12.5
vpaddd 64(%rdi), %ymm7, %ymm2 #12.5
vpaddd 96(%rdi), %ymm7, %ymm3 #12.5
vpaddd 128(%rdi), %ymm7, %ymm4 #12.5
vpaddd 160(%rdi), %ymm7, %ymm5 #12.5
vpaddd 192(%rdi), %ymm7, %ymm6 #12.5
vpaddd 224(%rdi), %ymm7, %ymm8 #12.5
vmovdqu %ymm0, (%rdi) #12.5
vmovdqu %ymm1, 32(%rdi) #12.5
vmovdqu %ymm2, 64(%rdi) #12.5
vmovdqu %ymm3, 96(%rdi) #12.5
vmovdqu %ymm4, 128(%rdi) #12.5
vmovdqu %ymm5, 160(%rdi) #12.5
vmovdqu %ymm6, 192(%rdi) #12.5
vmovdqu %ymm8, 224(%rdi) #12.5
vzeroupper #13.1
ret #13.1
LLVM could just use:
.LCPI0_0:
.long 1 # 0x1
plus1(b*): # @plus1(b*)
vbroadcastss .LCPI0_0(%rip), %ymm0 # ymm0 = [1,1,1,1,1,1,1,1]
<a href="https://godbolt.org/z/vx4nGcor9">https://godbolt.org/z/vx4nGcor9</a></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>