<html>
<head>
<base href="https://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 --- - Missed optimization when mixing volatile with normal access"
href="https://llvm.org/bugs/show_bug.cgi?id=28829">28829</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization when mixing volatile with normal access
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ahmad@a3f.at
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Godbolt link: <a href="https://godbolt.org/g/9brNCj">https://godbolt.org/g/9brNCj</a>
int x;
static int y;
int f() { x = 1; *(volatile int *)(&x) = x; x = 2; return x;}
int g() { y = 1; *(volatile int *)(&y) = y; y = 2; return y;}
int h() { int z = 1; *(volatile int *)(&z) = z; z = 2; return z;}
with clang 3.8 -O2 on AMD64 compiles to:
f: # @f
movl $1, x(%rip)
movl $1, x(%rip)
movl $2, x(%rip)
movl $2, %eax
retq
g: # @g
movl $1, y(%rip)
movl $1, y(%rip)
movl $2, y(%rip)
movl $2, %eax
retq
h: # @h
movl $1, -4(%rsp)
movl $1, -4(%rsp)
movl $2, %eax
retq
Is this intended behavior? My opinion is that the first $1 written isn't
necessary and that the $2 written to y should have been optimized out as well.</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>